public void setData(MatrixExprWithData expressionData) { Vector[][][] inputDataVectors; this.exprData = expressionData; int[] shape = MatUtils.shape(expressionData.output); int numRows = shape[0]; int numCols = shape[1]; switch (this.animationsType) { case MultipleAnimationsTypes.ColColMatMul: // dot with elementary basis int[] rightShape = MatUtils.shape(expressionData.inputs[1]); inputDataVectors = new Vector[2][][]; inputDataVectors[0] = new Vector[rightShape[0]][]; inputDataVectors[1] = new Vector[rightShape[0]][]; double[][] intermediateResultsDot = new double[rightShape[0]][]; for (int i = 0; i < rightShape[0]; i++) { inputDataVectors[0][i] = new Vector[rightShape[1]]; inputDataVectors[1][i] = new Vector[rightShape[1]]; intermediateResultsDot[i] = new double[rightShape[1]]; for (int j = 0; j < rightShape[1]; j++) { inputDataVectors[0][i][j] = expressionData.inputs[1].GetColumnVector(j); inputDataVectors[1][i][j] = MatUtils.standardBasis(i, rightShape[0]); intermediateResultsDot[i][j] = Vector.ScalarProduct(inputDataVectors[0][i][j], inputDataVectors[1][i][j]); } } this.animationArrays[0].setData(inputDataVectors); // scale the left columns Vector[][][] inputDataVectorsScale = new Vector[2][][]; inputDataVectorsScale[0] = new Vector[rightShape[0]][]; inputDataVectorsScale[1] = new Vector[rightShape[0]][]; Vector[][] intermediateResultsScale = new Vector[rightShape[0]][]; for (int i = 0; i < rightShape[0]; i++) { inputDataVectorsScale[0][i] = new Vector[rightShape[1]]; inputDataVectorsScale[1][i] = new Vector[rightShape[1]]; intermediateResultsScale[i] = new Vector[rightShape[1]]; for (int j = 0; j < rightShape[1]; j++) { inputDataVectorsScale[0][i][j] = new Vector(new double[] { intermediateResultsDot[i][j] }); inputDataVectorsScale[1][i][j] = expressionData.inputs[0].GetColumnVector(i); intermediateResultsScale[i][j] = intermediateResultsDot[i][j] * inputDataVectorsScale[1][i][j]; } } this.animationArrays[1].setData(inputDataVectorsScale); Vector[][][] inputDataVectorsAdd = new Vector[rightShape[0]][][]; for (int i = 0; i < rightShape[0]; i++) { inputDataVectorsAdd[i] = new Vector[1][]; inputDataVectorsAdd[i][0] = new Vector[rightShape[1]]; for (int j = 0; j < rightShape[1]; j++) { inputDataVectorsAdd[i][0][j] = intermediateResultsScale[i][j]; } } this.animationArrays[2].setData(inputDataVectorsAdd); break; case MultipleAnimationsTypes.ColDisplay: inputDataVectors = new Vector[1][][]; inputDataVectors[0] = new Vector[1][]; inputDataVectors[0][0] = new Vector[numCols]; for (int i = 0; i < numCols; i++) { inputDataVectors[0][0][i] = expressionData.output.GetColumnVector(i); } this.animationArrays[0].setData(inputDataVectors); break; case MultipleAnimationsTypes.RowDisplay: inputDataVectors = new Vector[1][][]; inputDataVectors[0] = new Vector[1][]; inputDataVectors[0][0] = new Vector[1]; inputDataVectors[0][0][0] = expressionData.output.GetRowVector(0); this.animationArrays[0].setData(inputDataVectors); break; case MultipleAnimationsTypes.ColScale: inputDataVectors = new Vector[2][][]; inputDataVectors[0] = new Vector[1][]; inputDataVectors[0][0] = new Vector[numCols]; for (int i = 0; i < numCols; i++) { inputDataVectors[0][0][i] = expressionData.inputs[0].GetColumnVector(0); } inputDataVectors[1] = new Vector[1][]; inputDataVectors[1][0] = new Vector[numCols]; for (int i = 0; i < numCols; i++) { inputDataVectors[1][0][i] = expressionData.inputs[1].GetColumnVector(i); } this.animationArrays[0].setData(inputDataVectors); break; case MultipleAnimationsTypes.RowScale: inputDataVectors = new Vector[2][][]; inputDataVectors[0] = new Vector[numRows][]; for (int i = 0; i < numRows; i++) { inputDataVectors[0][i] = new Vector[1]; inputDataVectors[0][i][0] = expressionData.inputs[0].GetRowVector(0); } inputDataVectors[1] = new Vector[numRows][]; for (int i = 0; i < numRows; i++) { inputDataVectors[1][i] = new Vector[1]; inputDataVectors[1][i][0] = expressionData.inputs[1].GetRowVector(i); } this.animationArrays[0].setData(inputDataVectors); break; case MultipleAnimationsTypes.ColAdd: inputDataVectors = new Vector[2][][]; inputDataVectors[0] = new Vector[1][]; inputDataVectors[0][0] = new Vector[numCols]; for (int i = 0; i < numCols; i++) { inputDataVectors[0][0][i] = expressionData.inputs[0].GetColumnVector(i); } inputDataVectors[1] = new Vector[1][]; inputDataVectors[1][0] = new Vector[numCols]; for (int i = 0; i < numCols; i++) { inputDataVectors[1][0][i] = expressionData.inputs[1].GetColumnVector(i); } this.animationArrays[0].setData(inputDataVectors); break; case MultipleAnimationsTypes.RowAdd: inputDataVectors = new Vector[2][][]; inputDataVectors[0] = new Vector[numRows][]; for (int i = 0; i < numRows; i++) { inputDataVectors[0][i] = new Vector[1]; inputDataVectors[0][i][0] = expressionData.inputs[0].GetRowVector(i); } inputDataVectors[1] = new Vector[numRows][]; for (int i = 0; i < numRows; i++) { inputDataVectors[1][i] = new Vector[1]; inputDataVectors[1][i][0] = expressionData.inputs[1].GetRowVector(i); } this.animationArrays[0].setData(inputDataVectors); break; case MultipleAnimationsTypes.ColSubtract: // scale first inputDataVectors = new Vector[2][][]; inputDataVectors[0] = new Vector[1][]; inputDataVectors[0][0] = new Vector[numCols]; for (int i = 0; i < numCols; i++) { inputDataVectors[0][0][i] = new Vector(new double[] { -1 }); } inputDataVectors[1] = new Vector[1][]; inputDataVectors[1][0] = new Vector[numCols]; for (int i = 0; i < numCols; i++) { inputDataVectors[1][0][i] = expressionData.inputs[1].GetColumnVector(i); } this.animationArrays[0].setData(inputDataVectors); // then add inputDataVectors = new Vector[2][][]; inputDataVectors[0] = new Vector[1][]; inputDataVectors[0][0] = new Vector[numCols]; for (int i = 0; i < numCols; i++) { inputDataVectors[0][0][i] = expressionData.inputs[0].GetColumnVector(i); } inputDataVectors[1] = new Vector[1][]; inputDataVectors[1][0] = new Vector[numCols]; for (int i = 0; i < numCols; i++) { inputDataVectors[1][0][i] = -1 * expressionData.inputs[1].GetColumnVector(i); } this.animationArrays[1].setData(inputDataVectors); break; case MultipleAnimationsTypes.RowSubtract: // scale first inputDataVectors = new Vector[2][][]; inputDataVectors[0] = new Vector[numRows][]; for (int i = 0; i < numRows; i++) { inputDataVectors[0][i] = new Vector[1]; inputDataVectors[0][i][0] = new Vector(new double[] { -1 }); } inputDataVectors[1] = new Vector[numRows][]; for (int i = 0; i < numRows; i++) { inputDataVectors[1][i] = new Vector[1]; inputDataVectors[1][i][0] = expressionData.inputs[1].GetRowVector(i); } this.animationArrays[0].setData(inputDataVectors); // then add inputDataVectors = new Vector[2][][]; inputDataVectors[0] = new Vector[numRows][]; for (int i = 0; i < numRows; i++) { inputDataVectors[0][i] = new Vector[1]; inputDataVectors[0][i][0] = expressionData.inputs[0].GetRowVector(i); } inputDataVectors[1] = new Vector[numRows][]; for (int i = 0; i < numRows; i++) { inputDataVectors[1][i] = new Vector[1]; inputDataVectors[1][i][0] = -1 * expressionData.inputs[1].GetRowVector(i); } this.animationArrays[1].setData(inputDataVectors); break; case MultipleAnimationsTypes.DotProduct: inputDataVectors = new Vector[2][][]; inputDataVectors[0] = new Vector[1][]; inputDataVectors[0][0] = new Vector[1]; inputDataVectors[0][0][0] = expressionData.inputs[0].GetRowVector(0); inputDataVectors[1] = new Vector[1][]; inputDataVectors[1][0] = new Vector[1]; inputDataVectors[1][0][0] = expressionData.inputs[1].GetColumnVector(0); this.animationArrays[0].setData(inputDataVectors); break; default: throw new Exception("Unsupported MultipleAnimationsTypes"); break; } }