User Tools

Site Tools


visual3d:documentation:pipeline:expressions:least_squares_fitting_of_data

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
visual3d:documentation:pipeline:expressions:least_squares_fitting_of_data [2024/06/19 12:49] sgrangervisual3d:documentation:pipeline:expressions:least_squares_fitting_of_data [2025/01/24 18:53] (current) – [Best Fit Plane] wikisysop
Line 1: Line 1:
-{{{{{{{{this page contains a list of all functions that are used to find a line or plane of best fit to your data.+===== Least Squares Fitting of Data =====
  
-===== best fit plane =====+This page contains a list of all of [[visual3d:documentation:pipeline:expressions:expressions_overview|Evaluate_Expression]]'s functions that are used to find a line or plane of best fit to your data.
  
-**best_fit_plane**(signal, start_event_signal, end_event_signal) - find a plane that fits the path of a point from a start event to an end event.+==== Best Fit Plane ====
  
-[[[https://en.wikipedia.org/wiki/plane_%28geometry%29#point-normal_form_and_general_form_of_the_equation_of_a_plane|the resulting plane is defined by 4 components]]+**Best_Fit_Plane**(signal, start_event_signal, end_event_signal) - Finds a plane that fits the path of a point from a start event to an end event. [[https://en.wikipedia.org/wiki/Plane_%28geometry%29#Point-normal_form_and_general_form_of_the_equation_of_a_plane|The resulting plane is defined by 4 components]].
-example: compute a best_plane_fit for one signal across a range of frames +
-**evaluate_expression** +
-/expression=best_fit_plane(current_signal,event_label::original::start,event_label::original::end) +
-/signal_types=target +
-/signal_folder=original +
-/signal_names=lsk_1 +
-/result_types=metric +
-/result_folders=processed +
-/result_name=lsk1_plane +
-/apply_as_suffix_to_signal_name=true +
-**;** +
-example: compute a best_plane_fit for multiple signals at each frame of data +
-**evaluate_expression** +
-/expression=best_fit_plane(current_signal) +
-/signal_types=target +
-/signal_folder=original +
-/signal_names=lsk_1+lsk_2+lsk_3 +
-/result_types=derived +
-/result_folders=processed +
-/result_name=lsk_plane +
-/apply_as_suffix_to_signal_name=true +
-**;** +
-===== best fit circle =====+
  
-**best_fit_circle**(signalstart_event_signalend_event_signal)+The general form of the equation of a plane in 3D is ax+by+cz+d = 0 where 𝑎𝑏and 𝑐 are the components of the normal vector which is perpendicular to the plane or any vector parallel to the plane.
  
-fit a 2d circle to the path of a signal. +If (𝑥0,𝑦0,𝑧0)is point that lies on the plane, then 𝑑=−(𝑎𝑥0+𝑏𝑦0+𝑐𝑧0) and as 𝑎𝑥+𝑏𝑦+𝑐𝑧−(𝑎𝑥0+𝑏𝑦0+𝑐𝑧0)=0.
-the algorithm computes a best fit plane to the datarotates this plane into principal plane, computes the center and radius, the rotates these values back into the original plane+
-the result is 4 components; the x,y,z location of the origin and the radius. +
-\\+
  
 +The result of the Best_Fit_Plane function is a signal with the fource components (a,b,c,d)
  
-===== best fit sphere =====+<code> 
 +! Example: Compute a Best_Plane_Fit for one signal across a range of frames 
 +Evaluate_Expression 
 +/EXPRESSION=Best_Fit_Plane(CURRENT_SIGNAL,EVENT_LABEL::ORIGINAL::START,EVENT_LABEL::ORIGINAL::END) 
 +/SIGNAL_TYPES=TARGET 
 +/SIGNAL_FOLDER=ORIGINAL 
 +/SIGNAL_NAMES=LSK_1 
 +/RESULT_TYPES=METRIC 
 +/RESULT_FOLDERS=PROCESSED 
 +/RESULT_NAME=LSK1_PLANE 
 +/APPLY_AS_SUFFIX_TO_SIGNAL_NAME=TRUE 
 +
 +</code>
  
-**best_fit_sphere**(signal,start_event_signal,end_event_signal)+<code> 
 +! Example: Compute a Best_Plane_Fit for multiple signals at each frame of data 
 +Evaluate_Expression 
 +/EXPRESSION=Best_Fit_Plane(CURRENT_SIGNAL) 
 +/SIGNAL_TYPES=TARGET 
 +/SIGNAL_FOLDER=ORIGINAL 
 +/SIGNAL_NAMES=LSK_1+LSK_2+LSK_3 
 +/RESULT_TYPES=DERIVED 
 +/RESULT_FOLDERS=PROCESSED 
 +/RESULT_NAME=LSK_PLANE 
 +/APPLY_AS_SUFFIX_TO_SIGNAL_NAME=TRUE 
 +
 +</code>
  
-example : fit a sphere to 6 points on a diamond +==== Best Fit Circle ====
-create 6 targets representing the vertices+
  
-[[visual3d:documentation:pipeline:signal_commands:create_target|create_target]] +**Best_Fit_Circle**(signalstart_event_signalend_event_signal) - Fits a 2D circle to the path of a signal.
-/signal_names=v1 +
-! /signal_description= +
-/expression=vector((0.5+0*frame_numbers::original::frames),0,0) +
-! /include_calfile=false +
-**;*+
-[[visual3d:documentation:pipeline:signal_commands:create_target|create_target]] +
-/signal_names=v2 +
-! /signal_description= +
-/expression=vector((-0.5+0*frame_numbers::original::frames),0,0) +
-! /include_calfile=false +
-**;** +
-[[visual3d:documentation:pipeline:signal_commands:create_target|create_target]] +
-/signal_names=v3 +
-! /signal_description= +
-/expression=vector((0,0.5+0*frame_numbers::original::frames),0) +
-! /include_calfile=false +
-**;** +
-[[visual3d:documentation:pipeline:signal_commands:create_target|create_target]] +
-/signal_names=v4 +
-! /signal_description= +
-/expression=vector((0,-0.5+0*frame_numbers::original::frames),0) +
-! /include_calfile=false +
-**;** +
-[[visual3d:documentation:pipeline:signal_commands:create_target|create_target]] +
-/signal_names=v5 +
-! /signal_description= +
-/expression=vector((0,0,0.5+0*frame_numbers::original::frames)) +
-! /include_calfile=false +
-**;** +
-[[visual3d:documentation:pipeline:signal_commands:create_target|create_target]] +
-/signal_names=v6 +
-! /signal_description= +
-/expression=vector((0,0,-0.5+0*frame_numbers::original::frames)) +
-! /include_calfile=false +
-**;** +
-**evaluate_expression** +
-/expression=best_fit_sphere(current_signal) +
-/signal_types=target +
-/signal_folder=original +
-/signal_names=v1+v2+v3+v4+v5+v6 +
-/result_types=derived +
-! /result_folders=processed +
-/result_name=sphere +
-! /apply_as_suffix_to_signal_name=false +
-**;** +
-note that targets are created and the sphere computed has each target on its surface. sphere1.jpgsphere6view.jpg+
  
-example : create target where each frame is on a random location on the surface of sphere of radius 1 +The algorithm computes best fit plane to the data, rotates this plane into principal planecomputes the center and radius, the rotates these values back into the original plane. The result is 4 components
-**evaluate_expression** +  - the origin's X-coordinate
-/expression=rand(-pi(),pi(),frame_numbers::original::frames) +  the origin's Y-coordinate
-/result_types=derived +  - the origin's Z-coordinateand 
-/result_folders=radius +  - the radius.
-/result_name=vertical +
-! /apply_as_suffix_to_signal_name=false +
-**;** +
-**evaluate_expression** +
-/expression=rand(0,2*pi(),frame_numbers::original::frames) +
-/result_types=derived +
-/result_folders=radius +
-/result_name=horizontal +
-! /apply_as_suffix_to_signal_name=false +
-**;** +
-[[visual3d:documentation:pipeline:signal_commands:create_target|create_target]] +
-/signal_names=sphere +
-! /signal_description= +
-/expression=vector( +
-cos(derived::radius::vertical)*cos(derived::radius::horizontal), +
--cos(derived::radius::vertical)*sin(derived::radius::horizontal), +
-sin(derived::radius::vertical)) +
-! /include_calfile=false +
-**;** +
-**evaluate_expression** +
-/expression=best_fit_sphere(current_signal) +
-/signal_types=target +
-/signal_folder=original +
-/signal_names=sphere +
-/result_types=derived +
-! /result_folders=processed +
-/result_name=sphere +
-! /apply_as_suffix_to_signal_name=false +
-**;** +
-random8view.jpg +
-sphererandom.jpg +
-===== simple linear regression =====+
  
-**simple_linear_regression**(signal1, signal2, start_event, end_event); - fit a signal to a line. y mx + b.+==== Best Fit Sphere ====
  
-signal2 = m signal1 + b +**Best_Fit_Sphere**(signal,start_event_signal,end_event_signal) Fits a 3D sphere to the path of a signal.
-an explanation of the calculation can be found [[visual3d:documentation:statistics:compute_linear_regression|here]] or [[[https://en.wikipedia.org/wiki/simple_linear_regression|here]]] +
-signal1 and signal2 are one component signals +
-resulting metric signal contains 6 components +
-slope = m -> component 1 +
-intercept = b -> component 2 +
-siga = uncertainty in m -> component 3 +
-sigb = uncertainty in b -> component 4 +
-chi2 = chi square -> component 5 +
-q = the r^2 statistic -> component 6+
  
-}}}}}}}}+<code> 
 +! Example : Fit a sphere to 6 points on a DIAMOND 
 + 
 +! Create 6 TARGETS representing the Vertices 
 +Create_Target 
 +/SIGNAL_NAMES=V1 
 +! /SIGNAL_DESCRIPTION= 
 +/EXPRESSION=VECTOR((0.5+0*FRAME_NUMBERS::ORIGINAL::FRAMES),0,0) 
 +! /INCLUDE_CALFILE=FALSE 
 +
 + 
 +Create_Target 
 +/SIGNAL_NAMES=V2 
 +! /SIGNAL_DESCRIPTION= 
 +/EXPRESSION=VECTOR((-0.5+0*FRAME_NUMBERS::ORIGINAL::FRAMES),0,0) 
 +! /INCLUDE_CALFILE=FALSE 
 +
 + 
 +Create_Target 
 +/SIGNAL_NAMES=V3 
 +! /SIGNAL_DESCRIPTION= 
 +/EXPRESSION=VECTOR((0,0.5+0*FRAME_NUMBERS::ORIGINAL::FRAMES),0) 
 +! /INCLUDE_CALFILE=FALSE 
 +
 + 
 +Create_Target 
 +/SIGNAL_NAMES=V4 
 +! /SIGNAL_DESCRIPTION= 
 +/EXPRESSION=VECTOR((0,-0.5+0*FRAME_NUMBERS::ORIGINAL::FRAMES),0) 
 +! /INCLUDE_CALFILE=FALSE 
 +
 + 
 +Create_Target 
 +/SIGNAL_NAMES=V5 
 +! /SIGNAL_DESCRIPTION= 
 +/EXPRESSION=VECTOR((0,0,0.5+0*FRAME_NUMBERS::ORIGINAL::FRAMES)) 
 +! /INCLUDE_CALFILE=FALSE 
 +
 + 
 +Create_Target 
 +/SIGNAL_NAMES=V6 
 +! /SIGNAL_DESCRIPTION= 
 +/EXPRESSION=VECTOR((0,0,-0.5+0*FRAME_NUMBERS::ORIGINAL::FRAMES)) 
 +! /INCLUDE_CALFILE=FALSE 
 +
 + 
 +Evaluate_Expression 
 +/EXPRESSION=Best_Fit_Sphere(CURRENT_SIGNAL) 
 +/SIGNAL_TYPES=TARGET 
 +/SIGNAL_FOLDER=ORIGINAL 
 +/SIGNAL_NAMES=V1+V2+V3+V4+V5+V6 
 +/RESULT_TYPES=DERIVED 
 +! /RESULT_FOLDERS=PROCESSED 
 +/RESULT_NAME=SPHERE 
 +! /APPLY_AS_SUFFIX_TO_SIGNAL_NAME=FALSE 
 +
 +</code> 
 + 
 +Note that TARGETS are created and the sphere computed has each TARGET on its surface. 
 + 
 +{{:Sphere1.jpg}}{{:sphere6view.jpg}} 
 + 
 +<code> 
 +! Example : Create a TARGET where each frame is on a random location on the surface of a sphere of radius 1 
 +Evaluate_Expression 
 +/EXPRESSION=RAND(-PI(),PI(),FRAME_NUMBERS::ORIGINAL::FRAMES) 
 +/RESULT_TYPES=DERIVED 
 +/RESULT_FOLDERS=RADIUS 
 +/RESULT_NAME=VERTICAL 
 +! /APPLY_AS_SUFFIX_TO_SIGNAL_NAME=FALSE 
 +
 + 
 +Evaluate_Expression 
 +/EXPRESSION=RAND(0,2*PI(),FRAME_NUMBERS::ORIGINAL::FRAMES) 
 +/RESULT_TYPES=DERIVED 
 +/RESULT_FOLDERS=RADIUS 
 +/RESULT_NAME=HORIZONTAL 
 +! /APPLY_AS_SUFFIX_TO_SIGNAL_NAME=FALSE 
 +
 + 
 +Create_Target 
 +/SIGNAL_NAMES=SPHERE 
 +! /SIGNAL_DESCRIPTION= 
 +/EXPRESSION=VECTOR( 
 +COS(DERIVED::RADIUS::VERTICAL)*COS(DERIVED::RADIUS::HORIZONTAL), 
 +-COS(DERIVED::RADIUS::VERTICAL)*SIN(DERIVED::RADIUS::HORIZONTAL), 
 +SIN(DERIVED::RADIUS::VERTICAL)) 
 +! /INCLUDE_CALFILE=FALSE 
 +
 + 
 +Evaluate_Expression 
 +/EXPRESSION=Best_Fit_Sphere(CURRENT_SIGNAL) 
 +/SIGNAL_TYPES=TARGET 
 +/SIGNAL_FOLDER=ORIGINAL 
 +/SIGNAL_NAMES=SPHERE 
 +/RESULT_TYPES=DERIVED 
 +! /RESULT_FOLDERS=PROCESSED 
 +/RESULT_NAME=SPHERE 
 +! /APPLY_AS_SUFFIX_TO_SIGNAL_NAME=FALSE 
 +
 +</code> 
 + 
 +{{:random8view.jpg}} 
 +{{:sphereRandom.jpg}} 
 + 
 +==== Simple Linear Regression ==== 
 + 
 +**Simple_Linear_Regression**(signal1, signal2, start_event, end_event); - Fits a signal to a line given by the equation Y = mX + b where 
 + 
 +<code> 
 +Signal = m Signal1 + b 
 +</code> 
 + 
 +An explanation of the calculation can be found [[Visual3D:Documentation:Statistics:Compute_Linear_Regression|here]] or [[https://en.wikipedia.org/wiki/Simple_linear_regression|here]]. 
 + 
 +Signal1 and Signal2 are both one-component signals and the resulting METRIC contains 6 components: 
 +  - Slope = m -> Component 1 
 +  - Intercept = b -> Component 2 
 +  - Siga = uncertainty in m -> Component 3 
 +  - Sigb = uncertainty in b -> Component 4 
 +  - Chi2 = chi square -> Component 5 
 +  - Q = The R^2 statistic -> Component 6
visual3d/documentation/pipeline/expressions/least_squares_fitting_of_data.1718801397.txt.gz · Last modified: 2024/06/19 12:49 by sgranger