diff --git a/examples/Reduced_normal_equations.ipynb b/examples/Reduced_normal_equations.ipynb index 5b19876b77be10a63d55d1acad8682c8d295447f..a02a77e7cedb8c7bb0761b8a156e5f450e97cf74 100644 --- a/examples/Reduced_normal_equations.ipynb +++ b/examples/Reduced_normal_equations.ipynb @@ -31,7 +31,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, "outputs": [], "source": [ @@ -46,11 +46,86 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": { "scrolled": false }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Image: MRO/CTX/1085197697:073\n", + " IT Pos. Bias | 0 | 0.0\n", + " CT Pos. Bias | 1 | 0.0\n", + " Rad Pos. Bias | 2 | 0.0\n", + " IT Vel. Bias | 3 | 0.0\n", + " CT Vel. Bias | 4 | 0.0\n", + " Rad Vel. Bias | 5 | 0.0\n", + " Omega Bias | 6 | 0.0\n", + " Phi Bias | 7 | 0.0\n", + " Kappa Bias | 8 | 0.0\n", + " Omega Rate | 9 | 0.0\n", + " Phi Rate | 10 | 0.0\n", + " Kappa Rate | 11 | 0.0\n", + " Omega Accl | 12 | 0.0\n", + " Phi Accl | 13 | 0.0\n", + " Kappa Accl | 14 | 0.0\n", + " Focal Bias | 15 | 0.0\n", + "Image: MRO/CTX/1157902986:250\n", + " IT Pos. Bias | 0 | 0.0\n", + " CT Pos. Bias | 1 | 0.0\n", + " Rad Pos. Bias | 2 | 0.0\n", + " IT Vel. Bias | 3 | 0.0\n", + " CT Vel. Bias | 4 | 0.0\n", + " Rad Vel. Bias | 5 | 0.0\n", + " Omega Bias | 6 | 0.0\n", + " Phi Bias | 7 | 0.0\n", + " Kappa Bias | 8 | 0.0\n", + " Omega Rate | 9 | 0.0\n", + " Phi Rate | 10 | 0.0\n", + " Kappa Rate | 11 | 0.0\n", + " Omega Accl | 12 | 0.0\n", + " Phi Accl | 13 | 0.0\n", + " Kappa Accl | 14 | 0.0\n", + " Focal Bias | 15 | 0.0\n", + "Image: MRO/CTX/1096561308:045\n", + " IT Pos. Bias | 0 | 0.0\n", + " CT Pos. Bias | 1 | 0.0\n", + " Rad Pos. Bias | 2 | 0.0\n", + " IT Vel. Bias | 3 | 0.0\n", + " CT Vel. Bias | 4 | 0.0\n", + " Rad Vel. Bias | 5 | 0.0\n", + " Omega Bias | 6 | 0.0\n", + " Phi Bias | 7 | 0.0\n", + " Kappa Bias | 8 | 0.0\n", + " Omega Rate | 9 | 0.0\n", + " Phi Rate | 10 | 0.0\n", + " Kappa Rate | 11 | 0.0\n", + " Omega Accl | 12 | 0.0\n", + " Phi Accl | 13 | 0.0\n", + " Kappa Accl | 14 | 0.0\n", + " Focal Bias | 15 | 0.0\n", + "Image: MRO/CTX/1136952576:186\n", + " IT Pos. Bias | 0 | 0.0\n", + " CT Pos. Bias | 1 | 0.0\n", + " Rad Pos. Bias | 2 | 0.0\n", + " IT Vel. Bias | 3 | 0.0\n", + " CT Vel. Bias | 4 | 0.0\n", + " Rad Vel. Bias | 5 | 0.0\n", + " Omega Bias | 6 | 0.0\n", + " Phi Bias | 7 | 0.0\n", + " Kappa Bias | 8 | 0.0\n", + " Omega Rate | 9 | 0.0\n", + " Phi Rate | 10 | 0.0\n", + " Kappa Rate | 11 | 0.0\n", + " Omega Accl | 12 | 0.0\n", + " Phi Accl | 13 | 0.0\n", + " Kappa Accl | 14 | 0.0\n", + " Focal Bias | 15 | 0.0\n" + ] + } + ], "source": [ "all_parameters = {sn: get_sensor_parameters(sensor) for sn, sensor in sensors.items()}\n", "for sn, parameters in all_parameters.items():\n", @@ -61,9 +136,44 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Image: MRO/CTX/1085197697:073\n", + " Omega Bias | 6 | 0.0\n", + " Phi Bias | 7 | 0.0\n", + " Kappa Bias | 8 | 0.0\n", + " Omega Rate | 9 | 0.0\n", + " Phi Rate | 10 | 0.0\n", + " Kappa Rate | 11 | 0.0\n", + "Image: MRO/CTX/1157902986:250\n", + " Omega Bias | 6 | 0.0\n", + " Phi Bias | 7 | 0.0\n", + " Kappa Bias | 8 | 0.0\n", + " Omega Rate | 9 | 0.0\n", + " Phi Rate | 10 | 0.0\n", + " Kappa Rate | 11 | 0.0\n", + "Image: MRO/CTX/1096561308:045\n", + " Omega Bias | 6 | 0.0\n", + " Phi Bias | 7 | 0.0\n", + " Kappa Bias | 8 | 0.0\n", + " Omega Rate | 9 | 0.0\n", + " Phi Rate | 10 | 0.0\n", + " Kappa Rate | 11 | 0.0\n", + "Image: MRO/CTX/1136952576:186\n", + " Omega Bias | 6 | 0.0\n", + " Phi Bias | 7 | 0.0\n", + " Kappa Bias | 8 | 0.0\n", + " Omega Rate | 9 | 0.0\n", + " Phi Rate | 10 | 0.0\n", + " Kappa Rate | 11 | 0.0\n" + ] + } + ], "source": [ "# Solve for angles and angular rates\n", "solve_parameters = {sn: params[6:12] for sn, params in all_parameters.items()}\n", @@ -75,7 +185,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": { "scrolled": true }, @@ -86,7 +196,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, "outputs": [], "source": [ @@ -98,7 +208,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": {}, "outputs": [], "source": [ @@ -108,7 +218,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": {}, "outputs": [], "source": [ @@ -118,9 +228,31 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "iteration 0: sigma0 = 4.204919720360203\n", + "\n", + "corrections: mean = 0.05349160077573805 min = -14.251221291713048 max = 40.834990964537575\n", + "iteration 1: sigma0 = 1.3539063538494558\n", + "\n", + "corrections: mean = 2.7124445740181957e-06 min = -0.011426521506164248 max = 0.011842165594603658\n", + "iteration 2: sigma0 = 1.127336617096085\n", + "\n", + "corrections: mean = 4.600122255126198e-08 min = -1.8475863314383526e-06 max = 4.573929399245028e-06\n", + "iteration 3: sigma0 = 1.1273365324778626\n", + "\n", + "corrections: mean = 1.879394505450981e-11 min = -1.283151025419733e-09 max = 1.8514518745707175e-09\n", + "iteration 4: sigma0 = 1.127336532470605\n", + "\n", + "change in sigma0 of 7.257527911974648e-12 converged!\n" + ] + } + ], "source": [ "sensors = generate_sensors(cubes) # generate sensors\n", "cnet = io_controlnetwork.from_isis(network) # load in network\n", @@ -135,7 +267,7 @@ "iteration = 0\n", "V = compute_residuals(cnet, sensors)\n", "dX = np.zeros(W_params.shape[0]) #initialize for sigma calculatioN\n", - "sigma0 = compute_sigma(V, dX, W_params, W_observations)\n", + "sigma0 = compute_sigma0(V, dX, W_params, W_observations)\n", "print(f'iteration {iteration}: sigma0 = {sigma0}\\n')\n", "\n", "total_correction_dense = np.zeros(num_parameters)\n", @@ -153,7 +285,7 @@ " update_parameters(sensors, solve_parameters, cnet, dX, column_dict)\n", " \n", " V = compute_residuals(cnet, sensors)\n", - " sigma0 = compute_sigma(V, dX, W_params, W_observations)\n", + " sigma0 = compute_sigma0(V, dX, W_params, W_observations)\n", " sigma0 = np.sqrt((V.dot(W_observations).dot(V) + dX.dot(W_params).dot(dX))/dof)\n", " print(f'iteration {iteration}: sigma0 = {sigma0}\\n')\n", " \n", @@ -165,11 +297,31 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 10, "metadata": { "scrolled": true }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "corrections: mean = 0.05349160077573873 min = -14.251221291713076 max = 40.834990964537546\n", + "iteration 1: sigma0 = 1.353906353849451\n", + "\n", + "corrections: mean = 2.712443886869334e-06 min = -0.011426521492657233 max = 0.011842165579696888\n", + "iteration 2: sigma0 = 1.1273366170980164\n", + "\n", + "corrections: mean = 4.6016402655676494e-08 min = -1.8475512374681445e-06 max = 4.5737885812869825e-06\n", + "iteration 3: sigma0 = 1.1273365324789022\n", + "\n", + "corrections: mean = 3.7306738076770124e-12 min = -1.429027500961002e-09 max = 1.6954805056745274e-09\n", + "iteration 4: sigma0 = 1.1273365324578994\n", + "\n", + "change in sigma0 of 2.100275509064886e-11 converged!\n" + ] + } + ], "source": [ "sensors = generate_sensors(cubes) # generate sensors\n", "cnet = io_controlnetwork.from_isis(network) # load in network\n", @@ -197,7 +349,7 @@ " W_PP[point_id] = compute_point_weight(cnet, point_id)\n", " \n", "V = compute_residuals(cnet, sensors)\n", - "sigma0 = compute_sigma_sparse(V, np.zeros(total_corrections.shape), W_CC_sparse, W_PP, W_observations, column_dict)\n", + "sigma0 = compute_sigma0_sparse(V, np.zeros(total_corrections.shape), W_CC_sparse, W_PP, W_observations, column_dict)\n", " \n", "# Start iteration logic\n", "for i in range(max_iterations):\n", @@ -266,7 +418,7 @@ "\n", " update_parameters(sensors, solve_parameters, cnet, updates, column_dict)\n", " V = compute_residuals(cnet, sensors)\n", - " sigma0 = compute_sigma_sparse(V, updates, W_CC_sparse, W_PP, W_observations, column_dict)\n", + " sigma0 = compute_sigma0_sparse(V, updates, W_CC_sparse, W_PP, W_observations, column_dict)\n", " print(f'iteration {i+1}: sigma0 = {sigma0}\\n')\n", " \n", " if (abs(sigma0 - old_sigma0) < tol):\n", @@ -276,9 +428,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 11, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Sensor diff\n", + "-1.450808806424675e-09\n", + "1.2130136894938914e-09\n", + "Point diff\n", + "-2.297802850770303e-10\n", + "4.665956510052638e-10\n" + ] + } + ], "source": [ "print(\"Sensor diff\")\n", "print(np.min(total_correction_dense[:num_sensor_params].flatten() - total_corrections[:num_sensor_params]))\n", diff --git a/knoten/bundle.py b/knoten/bundle.py index 574d4f0a8e62409ae8f52988273c878264803b33..588b0c4074db191b29302851f990fa07437df6de 100644 --- a/knoten/bundle.py +++ b/knoten/bundle.py @@ -435,7 +435,7 @@ def update_parameters(sensors, parameters, network, updates, coefficient_columns for sn, sensor in sensors.items(): for i, param in enumerate(parameters[sn]): if i > coefficient_columns[sn][1]: - print('THIS SHOULD BE AN ACTUAL ERROR') + raise IndexError(f'parameter [{param.name}] at index [{i}] is beyond the max index [{coefficient_columns[sn][1]}].') current_value = sensor.getParameterValue(param.index) sensor.setParameterValue(param.index, current_value+updates[coefficient_columns[sn][0]+i]) @@ -446,7 +446,7 @@ def update_parameters(sensors, parameters, network, updates, coefficient_columns adj = updates[coefficient_columns[point_id][0]:coefficient_columns[point_id][1]] network.loc[network.id == point_id, ["adjustedX", "adjustedY", "adjustedZ"]] = ground_pt + adj -def compute_sigma(V, dX, W_parameters, W_observations): +def compute_sigma0(V, dX, W_parameters, W_observations): """ Computes the resulting standard deviation of the residuals for the current state of the bundle network. @@ -475,7 +475,7 @@ def compute_sigma(V, dX, W_parameters, W_observations): sigma0 = np.sqrt(VTPV/dof) return sigma0 -def compute_sigma_sparse(V, dX, W_sensors, W_points, W_observations, column_dict): +def compute_sigma0_sparse(V, dX, W_sensors, W_points, W_observations, column_dict): """ Computes the resulting standard deviation of the residuals for the current state of the bundle network. diff --git a/tests/test_bundle.py b/tests/test_bundle.py index 08c2838e95f309c583f799dbee0153137c7228a7..6b95d67fe5c4be7cd01e8131dec88d5d0f4f1e95 100644 --- a/tests/test_bundle.py +++ b/tests/test_bundle.py @@ -184,7 +184,7 @@ def test_compute_sigma0(): [0, 0, 0, -7, -8, -9]] ) dX = np.arange(-6, 0) - assert bundle.compute_sigma(V, dX, W_params, W_obs) == np.sqrt(7809 / 10) + assert bundle.compute_sigma0(V, dX, W_params, W_obs) == np.sqrt(7809 / 10) def test_compute_sigma0_sparse(): V = np.arange(0, 16) + 1 @@ -198,7 +198,7 @@ def test_compute_sigma0_sparse(): "image_1" : (0, 3), "point_1" : (3, 6) } - assert bundle.compute_sigma_sparse(V, dX, W_sensors, W_points, W_obs, column_dict) == np.sqrt(7809 / 10) + assert bundle.compute_sigma0_sparse(V, dX, W_sensors, W_points, W_obs, column_dict) == np.sqrt(7809 / 10) def test_compute_image_weight():