private void EhCurrentProjectInstanceChanged(object sender, Altaxo.Main.ProjectEventArgs e) { if (e?.ProjectEventKind == Main.ProjectEventKind.ProjectRenamed) { EhCurrentProjectFileNameChanged(e.NewName); } if (object.ReferenceEquals(Current.Project, _currentProject)) { return; } ComDebug.ReportInfo("{0}.EhCurrentProjectInstanceChanged", GetType().Name); if (null != _currentProject && null != _currentProject.GraphDocumentCollection) { _currentProject.GraphDocumentCollection.CollectionChanged -= EhGraphDocumentRenamed; } _currentProject = Current.Project; if (null != _currentProject) { _currentProject.GraphDocumentCollection.CollectionChanged += EhGraphDocumentRenamed; EhCurrentProjectFileNameChanged(Current.IProjectService.CurrentProjectFileName); } }
/// <summary> /// Closes a project. If the project is dirty, the user is asked for saving the project. /// </summary> public void CloseProject() { if (CurrentOpenProject != null) { System.ComponentModel.CancelEventArgs e = new System.ComponentModel.CancelEventArgs(); if (this.CurrentOpenProject.IsDirty) { AskForSavingOfProject(e); } if (e.Cancel == false) { //if (saveCombinePreferencies) // SaveCombinePreferences(CurrentOpenCombine, openCombineFileName); Altaxo.AltaxoDocument closedProject = CurrentOpenProject; //CurrentSelectedProject = null; //CurrentOpenCombine = CurrentSelectedCombine = null; openProjectFileName = null; WorkbenchSingleton.Workbench.CloseAllViews(); OnProjectClosed(new ProjectEventArgs(closedProject)); //closedProject.Dispose(); // now create a new project CurrentOpenProject = new Altaxo.AltaxoDocument(); OnProjectOpened(new ProjectEventArgs(CurrentOpenProject)); } } }
/// <summary> /// Sets the current project instance and file name. No events raised (events should be raised by the caller). /// The old project instance will be disposed of. /// </summary> /// <param name="project">The new project.</param> /// <param name="projectFileName">Name of the new project file (for internally build instances, null).</param> private void SetCurrentProject(Altaxo.AltaxoDocument project, string projectFileName) { Altaxo.AltaxoDocument oldProject = _currentProject; string oldProjectFileName = _currentProjectFileName; if (null != _currentProject) { _currentProject.DirtyChanged -= EhProjectDirtyChanged; } _currentProject = project; _currentProjectFileName = projectFileName; if (_currentProject != null) { _currentProject.DirtyChanged += this.EhProjectDirtyChanged; } if (!object.ReferenceEquals(oldProject, _currentProject)) // Project instance has changed { if (null != oldProject) { try { oldProject.Dispose(); } catch (Exception ex) { } } } }
/// <summary> /// Sets the current project instance and file name. No events raised (events should be raised by the caller). /// The old project instance will be disposed of. /// </summary> /// <param name="project">The new project.</param> /// <param name="projectFileName">Name of the new project file (for internally build instances, null).</param> private void SetCurrentProject(Altaxo.AltaxoDocument project, string projectFileName) { Altaxo.AltaxoDocument oldProject = CurrentOpenProject; string oldProjectFileName = _currentProjectFileName; if (null != _currentProject) { _currentProject.IsDirtyChanged -= EhProjectDirtyChanged; } _currentProject = project; _currentProjectFileName = projectFileName; if (_currentProject != null) { _currentProject.IsDirtyChanged += EhProjectDirtyChanged; } if (!object.ReferenceEquals(oldProject, _currentProject)) // Project instance has changed { if (null != oldProject) { try { oldProject.Dispose(); } catch (Exception ex) { } } } }
public void Dispose() { ComDebug.ReportInfo("{0}.Dispose", this.GetType().Name); if (null != _currentProject && null != _currentProject.GraphDocumentCollection) { _currentProject.GraphDocumentCollection.CollectionChanged -= EhGraphDocumentRenamed; _currentProject = null; } Current.ProjectService.ProjectChanged -= EhCurrentProjectInstanceChanged; }
public void Dispose() { ComDebug.ReportInfo("{0}.Dispose", GetType().Name); if (null != _currentProject && null != _currentProject.GraphDocumentCollection) { _currentProject.GraphDocumentCollection.CollectionChanged -= EhGraphDocumentRenamed; _currentProject = null; } Current.IProjectService.ProjectChanged -= EhCurrentProjectInstanceChanged; }
/// <summary> /// Internal routine to save a project under a given name. /// </summary> /// <param name="projectToSave">The project to save.</param> /// <param name="filename"></param> public static void SaveProject(Altaxo.AltaxoDocument projectToSave, string filename) { using (var myStream = new System.IO.FileStream(filename, System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Write, System.IO.FileShare.None)) { using (var zippedStream = new System.IO.Compression.ZipArchive(myStream, System.IO.Compression.ZipArchiveMode.Create)) { var info = new Altaxo.Serialization.Xml.XmlStreamSerializationInfo(); projectToSave.SaveToZippedFile(zippedStream, info); } myStream.Close(); } }
protected static string TwoDimFFT(Altaxo.AltaxoDocument mainDocument, GUI.WorksheetController dg, out double[] rePart, out double[] imPart) { int rows = dg.Doc.DataColumns.RowCount; int cols = dg.Doc.DataColumns.ColumnCount; // reserve two arrays (one for real part, which is filled with the table contents) // and the imaginary part - which is left zero here) rePart = new double[rows * cols]; imPart = new double[rows * cols]; // fill the real part with the table contents for (int i = 0; i < cols; i++) { Altaxo.Data.INumericColumn col = dg.Doc[i] as Altaxo.Data.INumericColumn; if (null == col) { return(string.Format("Can't apply fourier transform, since column number {0}, name:{1} is not numeric", i, dg.Doc[i].FullName)); } for (int j = 0; j < rows; j++) { rePart[i * rows + j] = col[j]; } } // test it can be done if (!Pfa235FFT.CanFactorized(cols)) { return(string.Format("Can't apply fourier transform, since the number of cols ({0}) are not appropriate for this kind of fourier transform.", cols)); } if (!Pfa235FFT.CanFactorized(rows)) { return(string.Format("Can't apply fourier transform, since the number of rows ({0}) are not appropriate for this kind of fourier transform.", rows)); } // fourier transform Pfa235FFT fft = new Pfa235FFT(cols, rows); fft.FFT(rePart, imPart, FourierDirection.Forward); // replace the real part by the amplitude for (int i = 0; i < rePart.Length; i++) { rePart[i] = Math.Sqrt(rePart[i] * rePart[i] + imPart[i] * imPart[i]); } return(null); }
public static string TwoDimCenteredFFT(Altaxo.AltaxoDocument mainDocument, GUI.WorksheetController dg) { int rows = dg.Doc.DataColumns.RowCount; int cols = dg.Doc.DataColumns.ColumnCount; // reserve two arrays (one for real part, which is filled with the table contents) // and the imaginary part - which is left zero here) double[] rePart; double[] imPart; string stringresult = TwoDimFFT(mainDocument, dg, out rePart, out imPart); if (stringresult != null) { return(stringresult); } Altaxo.Data.DataTable table = new Altaxo.Data.DataTable("Fourieramplitude of " + dg.Doc.Name); // Fill the Table so that the zero frequency point is in the middle // this means for the point order: // for even number of points, i.e. 8 points, the frequencies are -3, -2, -1, 0, 1, 2, 3, 4 (the frequency 4 is the nyquist part) // for odd number of points, i.e. 9 points, the frequencies are -4, -3, -2, -1, 0, 1, 2, 3, 4 (for odd number of points there is no nyquist part) table.Suspend(); int colsNegative = (cols - 1) / 2; // number of negative frequency points int colsPositive = cols - colsNegative; // number of positive (or null) frequency points int rowsNegative = (rows - 1) / 2; int rowsPositive = rows - rowsNegative; for (int i = 0; i < cols; i++) { int sc = i < colsNegative ? i + colsPositive : i - colsNegative;// source column index centered Altaxo.Data.DoubleColumn col = new Altaxo.Data.DoubleColumn(); for (int j = 0; j < rows; j++) { int sr = j < rowsNegative ? j + rowsPositive : j - rowsNegative; // source row index centered col[j] = rePart[sc * rows + sr]; } table.DataColumns.Add(col); } table.Resume(); mainDocument.DataTableCollection.Add(table); // create a new worksheet without any columns Current.ProjectService.CreateNewWorksheet(table); return(null); }
public static string Correlation(Altaxo.AltaxoDocument mainDocument, IWorksheetController dg) { int len = dg.SelectedDataColumns.Count; if (len == 0) { return("No column selected!"); // nothing selected } if (len > 2) { return("Too many columns selected!"); } if (!(dg.DataTable[dg.SelectedDataColumns[0]] is Altaxo.Data.DoubleColumn)) { return("First selected column is not numeric!"); } if (dg.SelectedDataColumns.Count == 2 && !(dg.DataTable[dg.SelectedDataColumns[1]] is Altaxo.Data.DoubleColumn)) { return("Second selected column is not numeric!"); } double[] arr1 = ((Altaxo.Data.DoubleColumn)dg.DataTable[dg.SelectedDataColumns[0]]).Array; double[] arr2 = arr1; if (dg.SelectedDataColumns.Count == 2) { arr2 = ((Altaxo.Data.DoubleColumn)dg.DataTable[dg.SelectedDataColumns[1]]).Array; } double[] result = new double[arr1.Length + arr2.Length - 1]; //Pfa235Convolution co = new Pfa235Convolution(arr1.Length); //co.Convolute(arr1, arr2, result, null, FourierDirection.Forward); Calc.Fourier.NativeFourierMethods.CorrelationNonCyclic(arr1, arr2, result); var col = new Altaxo.Data.DoubleColumn { Array = result }; dg.DataTable.DataColumns.Add(col, "Correlate"); return(null); }
public static string TwoDimFFT(Altaxo.AltaxoDocument mainDocument, GUI.WorksheetController dg) { int rows = dg.Doc.DataColumns.RowCount; int cols = dg.Doc.DataColumns.ColumnCount; // reserve two arrays (one for real part, which is filled with the table contents) // and the imaginary part - which is left zero here) double[] rePart; double[] imPart; string stringresult = TwoDimFFT(mainDocument, dg, out rePart, out imPart); if (stringresult != null) { return(stringresult); } Altaxo.Data.DataTable table = new Altaxo.Data.DataTable("Fourieramplitude of " + dg.Doc.Name); // Fill the Table table.Suspend(); for (int i = 0; i < cols; i++) { Altaxo.Data.DoubleColumn col = new Altaxo.Data.DoubleColumn(); for (int j = 0; j < rows; j++) { col[j] = rePart[i * rows + j]; } table.DataColumns.Add(col); } table.Resume(); mainDocument.DataTableCollection.Add(table); // create a new worksheet without any columns Current.ProjectService.CreateNewWorksheet(table); return(null); }
/// <summary> /// Asks the user for a file name for the current project, and then saves the project under the given name. /// </summary> public static void SaveProjectAs(Altaxo.AltaxoDocument projectToSave) { var dlg = new Altaxo.Gui.SaveFileOptions(); string description = StringParser.Parse("${res:Altaxo.FileFilter.ProjectFiles})"); dlg.AddFilter("*.axoprj", description); dlg.OverwritePrompt = true; dlg.AddExtension = true; if (!Current.Gui.ShowSaveFileDialog(dlg)) { return; } try { SaveProject(projectToSave, dlg.FileName); } catch (Exception ex) { Current.Gui.ErrorMessageBox(ex.Message, "Error during saving of the mini project"); } }
private void EhCurrentProjectInstanceChanged(object sender, Altaxo.Main.ProjectEventArgs e) { if (e?.ProjectEventKind == Main.ProjectEventKind.ProjectRenamed) EhCurrentProjectFileNameChanged(e.NewName); if (object.ReferenceEquals(Current.Project, _currentProject)) return; ComDebug.ReportInfo("{0}.EhCurrentProjectInstanceChanged", this.GetType().Name); if (null != _currentProject && null != _currentProject.GraphDocumentCollection) { _currentProject.GraphDocumentCollection.CollectionChanged -= EhGraphDocumentRenamed; } _currentProject = Current.Project; if (null != _currentProject) { _currentProject.GraphDocumentCollection.CollectionChanged += EhGraphDocumentRenamed; EhCurrentProjectFileNameChanged(Current.ProjectService.CurrentProjectFileName); } }
/// <summary> /// Closes a project. If the project is dirty, the user is asked for saving the project. /// </summary> public void CloseProject() { if (CurrentOpenProject != null) { System.ComponentModel.CancelEventArgs e = new System.ComponentModel.CancelEventArgs(); if (this.CurrentOpenProject.IsDirty) AskForSavingOfProject(e); if (e.Cancel == false) { //if (saveCombinePreferencies) // SaveCombinePreferences(CurrentOpenCombine, openCombineFileName); Altaxo.AltaxoDocument closedProject = CurrentOpenProject; //CurrentSelectedProject = null; //CurrentOpenCombine = CurrentSelectedCombine = null; openProjectFileName = null; WorkbenchSingleton.Workbench.CloseAllViews(); OnProjectClosed(new ProjectEventArgs(closedProject)); //closedProject.Dispose(); // now create a new project CurrentOpenProject = new Altaxo.AltaxoDocument(); OnProjectOpened(new ProjectEventArgs(CurrentOpenProject)); } } }
public static void StatisticsOnColumns( Altaxo.AltaxoDocument mainDocument, Altaxo.Data.DataTable srctable, IAscendingIntegerCollection selectedColumns, IAscendingIntegerCollection selectedRows ) { bool bUseSelectedColumns = (null != selectedColumns && 0 != selectedColumns.Count); int numcols = bUseSelectedColumns ? selectedColumns.Count : srctable.DataColumns.ColumnCount; bool bUseSelectedRows = (null != selectedRows && 0 != selectedRows.Count); if (numcols == 0) { return; // nothing selected } Data.DataTable table = null; // the created table // add a text column and some double columns // note: statistics is only possible for numeric columns since // otherwise in one column doubles and i.e. dates are mixed, which is not possible // 1st column is the name of the column of which the statistics is made Data.TextColumn colCol = new Data.TextColumn(); // 2nd column is the mean Data.DoubleColumn colMean = new Data.DoubleColumn(); // 3rd column is the standard deviation Data.DoubleColumn colSd = new Data.DoubleColumn(); // 4th column is the standard e (N) Data.DoubleColumn colSe = new Data.DoubleColumn(); // 5th column is the sum Data.DoubleColumn colSum = new Data.DoubleColumn(); // 6th column is the number of items for statistics Data.DoubleColumn colN = new Data.DoubleColumn(); int currRow = 0; for (int si = 0; si < numcols; si++) { Altaxo.Data.DataColumn col = bUseSelectedColumns ? srctable[selectedColumns[si]] : srctable[si]; if (!(col is Altaxo.Data.INumericColumn)) { continue; } int rows = bUseSelectedRows ? selectedRows.Count : srctable.DataColumns.RowCount; if (rows == 0) { continue; } // now do the statistics Data.INumericColumn ncol = (Data.INumericColumn)col; double sum = 0; double sumsqr = 0; int NN = 0; for (int i = 0; i < rows; i++) { double val = bUseSelectedRows ? ncol[selectedRows[i]] : ncol[i]; if (Double.IsNaN(val)) { continue; } NN++; sum += val; sumsqr += (val * val); } // now fill a new row in the worksheet if (NN > 0) { double mean = sum / NN; double ymy0sqr = sumsqr - sum * sum / NN; if (ymy0sqr < 0) { ymy0sqr = 0; // if this is lesser zero, it is a rounding error, so set it to zero } double sd = NN > 1 ? Math.Sqrt(ymy0sqr / (NN - 1)) : 0; double se = sd / Math.Sqrt(NN); colCol[currRow] = col.Name; colMean[currRow] = mean; // mean colSd[currRow] = sd; colSe[currRow] = se; colSum[currRow] = sum; colN[currRow] = NN; currRow++; // for the next column } } // for all selected columns if (currRow != 0) { table = new Altaxo.Data.DataTable("Statistics of " + srctable.Name); table.DataColumns.Add(colCol, "Col", Altaxo.Data.ColumnKind.X); // new : add a copy of all property columns; can be usefull for (int i = 0; i < srctable.PropertyColumnCount; i++) { DataColumn originalColumn = srctable.PropertyColumns[i]; DataColumn clonedColumn = (DataColumn)originalColumn.Clone(); clonedColumn.Clear(); for (int si = 0; si < numcols; si++) { int idx = bUseSelectedColumns ? selectedColumns[si] : si; clonedColumn[si] = originalColumn[idx]; } table.DataColumns.Add(clonedColumn, srctable.PropertyColumns.GetColumnName(i), srctable.PropertyColumns.GetColumnKind(i), srctable.PropertyColumns.GetColumnGroup(i)); } table.DataColumns.Add(colMean, "Mean"); table.DataColumns.Add(colSd, "Sd"); table.DataColumns.Add(colSe, "Se"); table.DataColumns.Add(colSum, "Sum"); table.DataColumns.Add(colN, "N"); mainDocument.DataTableCollection.Add(table); // create a new worksheet without any columns Current.ProjectService.CreateNewWorksheet(table); } }
public static void StatisticsOnRows( Altaxo.AltaxoDocument mainDocument, Altaxo.Data.DataTable srctable, IAscendingIntegerCollection selectedColumns, IAscendingIntegerCollection selectedRows ) { bool bUseSelectedColumns = (null != selectedColumns && 0 != selectedColumns.Count); int numcols = bUseSelectedColumns ? selectedColumns.Count : srctable.DataColumns.ColumnCount; if (numcols == 0) { return; // nothing selected } bool bUseSelectedRows = (null != selectedRows && 0 != selectedRows.Count); int numrows = bUseSelectedRows ? selectedRows.Count : srctable.DataColumns.RowCount; if (numrows == 0) { return; } Altaxo.Data.DataTable table = new Altaxo.Data.DataTable(); // add a text column and some double columns // note: statistics is only possible for numeric columns since // otherwise in one column doubles and i.e. dates are mixed, which is not possible // 1st column is the mean, and holds the sum during the calculation Data.DoubleColumn c1 = new Data.DoubleColumn(); // 2rd column is the standard deviation, and holds the square sum during calculation Data.DoubleColumn c2 = new Data.DoubleColumn(); // 3th column is the standard e (N) Data.DoubleColumn c3 = new Data.DoubleColumn(); // 4th column is the sum Data.DoubleColumn c4 = new Data.DoubleColumn(); // 5th column is the number of items for statistics Data.DoubleColumn c5 = new Data.DoubleColumn(); table.DataColumns.Add(c1, "Mean"); table.DataColumns.Add(c2, "sd"); table.DataColumns.Add(c3, "se"); table.DataColumns.Add(c4, "Sum"); table.DataColumns.Add(c5, "N"); table.Suspend(); // first fill the cols c1, c2, c5 with zeros because we want to sum up for (int i = 0; i < numrows; i++) { c1[i] = 0; c2[i] = 0; c5[i] = 0; } for (int si = 0; si < numcols; si++) { Altaxo.Data.DataColumn col = bUseSelectedColumns ? srctable[selectedColumns[si]] : srctable[si]; if (!(col is Altaxo.Data.INumericColumn)) { continue; } // now do the statistics Data.INumericColumn ncol = (Data.INumericColumn)col; for (int i = 0; i < numrows; i++) { double val = bUseSelectedRows ? ncol[selectedRows[i]] : ncol[i]; if (Double.IsNaN(val)) { continue; } c1[i] += val; c2[i] += val * val; c5[i] += 1; } } // for all selected columns // now calculate the statistics for (int i = 0; i < numrows; i++) { // now fill a new row in the worksheet double NN = c5[i]; double sum = c1[i]; double sumsqr = c2[i]; if (NN > 0) { double mean = c1[i] / NN; double ymy0sqr = sumsqr - sum * sum / NN; if (ymy0sqr < 0) { ymy0sqr = 0; // if this is lesser zero, it is a rounding error, so set it to zero } double sd = NN > 1 ? Math.Sqrt(ymy0sqr / (NN - 1)) : 0; double se = sd / Math.Sqrt(NN); c1[i] = mean; // mean c2[i] = sd; c3[i] = se; c4[i] = sum; c5[i] = NN; } } // for all rows // if a table was created, we add the table to the data set and // create a worksheet if (null != table) { table.Resume(); mainDocument.DataTableCollection.Add(table); // create a new worksheet without any columns Current.ProjectService.CreateNewWorksheet(table); } }
/// <summary> /// Constructor. /// </summary> /// <param name="renamedProject">The project which was changed.</param> public ProjectEventArgs(Altaxo.AltaxoDocument renamedProject) { this.project = renamedProject; }
/// <summary> /// Makes a PCA (a principal component analysis) of the table or the selected columns / rows and stores the results in a newly created table. /// </summary> /// <param name="mainDocument">The main document of the application.</param> /// <param name="srctable">The table where the data come from.</param> /// <param name="selectedColumns">The selected columns.</param> /// <param name="selectedRows">The selected rows.</param> /// <param name="bHorizontalOrientedSpectrum">True if a spectrum is a single row, False if a spectrum is a single column.</param> /// <param name="maxNumberOfFactors">The maximum number of factors to calculate.</param> /// <returns></returns> public static string PrincipalComponentAnalysis( Altaxo.AltaxoDocument mainDocument, Altaxo.Data.DataTable srctable, IAscendingIntegerCollection selectedColumns, IAscendingIntegerCollection selectedRows, bool bHorizontalOrientedSpectrum, int maxNumberOfFactors ) { bool bUseSelectedColumns = (null != selectedColumns && 0 != selectedColumns.Count); int prenumcols = bUseSelectedColumns ? selectedColumns.Count : srctable.DataColumns.ColumnCount; // check for the number of numeric columns int numcols = 0; for (int i = 0; i < prenumcols; i++) { int idx = bUseSelectedColumns ? selectedColumns[i] : i; if (srctable[i] is Altaxo.Data.INumericColumn) { numcols++; } } // check the number of rows bool bUseSelectedRows = (null != selectedRows && 0 != selectedRows.Count); int numrows; if (bUseSelectedRows) { numrows = selectedRows.Count; } else { numrows = 0; for (int i = 0; i < numcols; i++) { int idx = bUseSelectedColumns ? selectedColumns[i] : i; numrows = Math.Max(numrows, srctable[idx].Count); } } // check that both dimensions are at least 2 - otherwise PCA is not possible if (numrows < 2) { return("At least two rows are neccessary to do Principal Component Analysis!"); } if (numcols < 2) { return("At least two numeric columns are neccessary to do Principal Component Analysis!"); } // Create a matrix of appropriate dimensions and fill it MatrixMath.BEMatrix matrixX; if (bHorizontalOrientedSpectrum) { matrixX = new MatrixMath.BEMatrix(numrows, numcols); int ccol = 0; // current column in the matrix for (int i = 0; i < prenumcols; i++) { int colidx = bUseSelectedColumns ? selectedColumns[i] : i; Altaxo.Data.INumericColumn col = srctable[colidx] as Altaxo.Data.INumericColumn; if (null != col) { for (int j = 0; j < numrows; j++) { int rowidx = bUseSelectedRows ? selectedRows[j] : j; matrixX[j, ccol] = col[rowidx]; } ++ccol; } } } // end if it was a horizontal oriented spectrum else // if it is a vertical oriented spectrum { matrixX = new MatrixMath.BEMatrix(numcols, numrows); int ccol = 0; // current column in the matrix for (int i = 0; i < prenumcols; i++) { int colidx = bUseSelectedColumns ? selectedColumns[i] : i; Altaxo.Data.INumericColumn col = srctable[colidx] as Altaxo.Data.INumericColumn; if (null != col) { for (int j = 0; j < numrows; j++) { int rowidx = bUseSelectedRows ? selectedRows[j] : j; matrixX[ccol, j] = col[rowidx]; } ++ccol; } } } // if it was a vertical oriented spectrum // now do PCA with the matrix MatrixMath.REMatrix factors = new MatrixMath.REMatrix(0, 0); MatrixMath.BEMatrix loads = new MatrixMath.BEMatrix(0, 0); MatrixMath.BEMatrix residualVariances = new MatrixMath.BEMatrix(0, 0); MatrixMath.HorizontalVector meanX = new MatrixMath.HorizontalVector(matrixX.Columns); // first, center the matrix MatrixMath.ColumnsToZeroMean(matrixX, meanX); MatrixMath.NIPALS_HO(matrixX, maxNumberOfFactors, 1E-9, factors, loads, residualVariances); // now we have to create a new table where to place the calculated factors and loads // we will do that in a vertical oriented manner, i.e. even if the loads are // here in horizontal vectors: in our table they are stored in (vertical) columns Altaxo.Data.DataTable table = new Altaxo.Data.DataTable("PCA of " + srctable.Name); // Fill the Table table.Suspend(); // first of all store the meanscore { double meanScore = MatrixMath.LengthOf(meanX); MatrixMath.NormalizeRows(meanX); Altaxo.Data.DoubleColumn col = new Altaxo.Data.DoubleColumn(); for (int i = 0; i < factors.Rows; i++) { col[i] = meanScore; } table.DataColumns.Add(col, "MeanFactor", Altaxo.Data.ColumnKind.V, 0); } // first store the factors for (int i = 0; i < factors.Columns; i++) { Altaxo.Data.DoubleColumn col = new Altaxo.Data.DoubleColumn(); for (int j = 0; j < factors.Rows; j++) { col[j] = factors[j, i]; } table.DataColumns.Add(col, "Factor" + i.ToString(), Altaxo.Data.ColumnKind.V, 1); } // now store the mean of the matrix { Altaxo.Data.DoubleColumn col = new Altaxo.Data.DoubleColumn(); for (int j = 0; j < meanX.Columns; j++) { col[j] = meanX[0, j]; } table.DataColumns.Add(col, "MeanLoad", Altaxo.Data.ColumnKind.V, 2); } // now store the loads - careful - they are horizontal in the matrix for (int i = 0; i < loads.Rows; i++) { Altaxo.Data.DoubleColumn col = new Altaxo.Data.DoubleColumn(); for (int j = 0; j < loads.Columns; j++) { col[j] = loads[i, j]; } table.DataColumns.Add(col, "Load" + i.ToString(), Altaxo.Data.ColumnKind.V, 3); } // now store the residual variances, they are vertical in the vector { Altaxo.Data.DoubleColumn col = new Altaxo.Data.DoubleColumn(); for (int i = 0; i < residualVariances.Rows; i++) { col[i] = residualVariances[i, 0]; } table.DataColumns.Add(col, "ResidualVariance", Altaxo.Data.ColumnKind.V, 4); } table.Resume(); mainDocument.DataTableCollection.Add(table); // create a new worksheet without any columns Current.ProjectService.CreateNewWorksheet(table); return(null); }
/// <summary> /// Closes a project. If the project is dirty, and <paramref name="withoutUserInteraction"/> is <c>false</c>, the user is asked to save the project. /// </summary> /// <param name="withoutUserInteraction">If <c>false</c> and the project is dirty, the user will be asked whether he really wants to close the project. /// If <c>true</c>, the project is closed without user interaction.</param> public void CloseProject(bool withoutUserInteraction) { if (CurrentOpenProject != null && CurrentOpenProject.IsDirty && !withoutUserInteraction) { System.ComponentModel.CancelEventArgs e = new System.ComponentModel.CancelEventArgs(); AskForSavingOfProject(e); if (true == e.Cancel) return; } var oldProject = _currentProject; var oldProjectName = _currentProjectFileName; if (oldProject != null) OnProjectChanged(new ProjectEventArgs(oldProject, oldProjectName, ProjectEventKind.ProjectClosing)); WorkbenchSingleton.Workbench.CloseAllViews(); SetCurrentProject(null, null); if (oldProject != null) OnProjectChanged(new ProjectEventArgs(oldProject, oldProjectName, ProjectEventKind.ProjectClosed)); // now create a new project OnProjectChanged(new ProjectEventArgs(null, null, ProjectEventKind.ProjectOpening)); var newProject = new Altaxo.AltaxoDocument(); SetCurrentProject(newProject, null); OnProjectChanged(new ProjectEventArgs(newProject, null, ProjectEventKind.ProjectOpened)); }
/// <summary> /// Disposes the whole project and sets the current project to null. /// </summary> public void DisposeProjectAndSetToNull() { if (this._currentProject != null) { this._currentProject.Dispose(); this._currentProject = null; } }
/// <summary> /// Multiplies selected columns to form a matrix. /// </summary> /// <param name="mainDocument"></param> /// <param name="srctable"></param> /// <param name="selectedColumns"></param> /// <returns>Null if successful, else the description of the error.</returns> /// <remarks>The user must select an even number of columns. All columns of the first half of the selection /// must have the same number of rows, and all columns of the second half of selection must also have the same /// number of rows. The first half of selected columns form a matrix of dimensions(firstrowcount,halfselected), and the second half /// of selected columns form a matrix of dimension(halfselected, secondrowcount). The resulting matrix has dimensions (firstrowcount,secondrowcount) and is /// stored in a separate worksheet.</remarks> public static string MultiplyColumnsToMatrix( Altaxo.AltaxoDocument mainDocument, Altaxo.Data.DataTable srctable, IAscendingIntegerCollection selectedColumns ) { // check that there are columns selected if (0 == selectedColumns.Count) { return("You must select at least two columns to multiply!"); } // selected columns must contain an even number of columns if (0 != selectedColumns.Count % 2) { return("You selected an odd number of columns. Please select an even number of columns to multiply!"); } // all selected columns must be numeric columns for (int i = 0; i < selectedColumns.Count; i++) { if (!(srctable[selectedColumns[i]] is Altaxo.Data.INumericColumn)) { return(string.Format("The column[{0}] (name:{1}) is not a numeric column!", selectedColumns[i], srctable[selectedColumns[i]].Name)); } } int halfselect = selectedColumns.Count / 2; // check that all columns from the first half of selected colums contain the same // number of rows int rowsfirsthalf = int.MinValue; for (int i = 0; i < halfselect; i++) { int idx = selectedColumns[i]; if (rowsfirsthalf < 0) { rowsfirsthalf = srctable[idx].Count; } else if (rowsfirsthalf != srctable[idx].Count) { return("The first half of selected columns have not all the same length!"); } } int rowssecondhalf = int.MinValue; for (int i = halfselect; i < selectedColumns.Count; i++) { int idx = selectedColumns[i]; if (rowssecondhalf < 0) { rowssecondhalf = srctable[idx].Count; } else if (rowssecondhalf != srctable[idx].Count) { return("The second half of selected columns have not all the same length!"); } } // now create the matrices to multiply from the MatrixMath.REMatrix firstMat = new MatrixMath.REMatrix(rowsfirsthalf, halfselect); for (int i = 0; i < halfselect; i++) { Altaxo.Data.INumericColumn col = (Altaxo.Data.INumericColumn)srctable[selectedColumns[i]]; for (int j = 0; j < rowsfirsthalf; j++) { firstMat[j, i] = col[j]; } } MatrixMath.BEMatrix secondMat = new MatrixMath.BEMatrix(halfselect, rowssecondhalf); for (int i = 0; i < halfselect; i++) { Altaxo.Data.INumericColumn col = (Altaxo.Data.INumericColumn)srctable[selectedColumns[i + halfselect]]; for (int j = 0; j < rowssecondhalf; j++) { secondMat[i, j] = col[j]; } } // now multiply the two matrices MatrixMath.BEMatrix resultMat = new MatrixMath.BEMatrix(rowsfirsthalf, rowssecondhalf); MatrixMath.Multiply(firstMat, secondMat, resultMat); // and store the result in a new worksheet Altaxo.Data.DataTable table = new Altaxo.Data.DataTable("ResultMatrix of " + srctable.Name); table.Suspend(); // first store the factors for (int i = 0; i < resultMat.Columns; i++) { Altaxo.Data.DoubleColumn col = new Altaxo.Data.DoubleColumn(); for (int j = 0; j < resultMat.Rows; j++) { col[j] = resultMat[j, i]; } table.DataColumns.Add(col, i.ToString()); } table.Resume(); mainDocument.DataTableCollection.Add(table); // create a new worksheet without any columns Current.ProjectService.CreateNewWorksheet(table); return(null); }
/// <summary> /// Constructor. /// </summary> /// <param name="renamedProject">The project renamed.</param> /// <param name="oldName">The old name of the project.</param> /// <param name="newName">The new name of the project.</param> public ProjectRenameEventArgs(Altaxo.AltaxoDocument renamedProject, string oldName, string newName) : base(renamedProject) { this.oldName = oldName; this.newName = newName; }