当前位置: 首页>>代码示例>>C#>>正文


C# DataTable.SuspendGetToken方法代码示例

本文整理汇总了C#中Altaxo.Data.DataTable.SuspendGetToken方法的典型用法代码示例。如果您正苦于以下问题:C# DataTable.SuspendGetToken方法的具体用法?C# DataTable.SuspendGetToken怎么用?C# DataTable.SuspendGetToken使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Altaxo.Data.DataTable的用法示例。


在下文中一共展示了DataTable.SuspendGetToken方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ExecuteAnalysis

		/// <summary>
		/// Makes a PLS (a partial least squares) 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="selectedPropertyColumns">The selected property column(s).</param>
		/// <param name="bHorizontalOrientedSpectrum">True if a spectrum is a single row, False if a spectrum is a single column.</param>
		/// <param name="plsOptions">Provides information about the max number of factors and the calculation of cross PRESS value.</param>
		/// <param name="preprocessOptions">Provides information about how to preprocess the spectra.</param>
		/// <returns></returns>
		public virtual string ExecuteAnalysis(
			Altaxo.AltaxoDocument mainDocument,
			Altaxo.Data.DataTable srctable,
			IAscendingIntegerCollection selectedColumns,
			IAscendingIntegerCollection selectedRows,
			IAscendingIntegerCollection selectedPropertyColumns,
			bool bHorizontalOrientedSpectrum,
			MultivariateAnalysisOptions plsOptions,
			SpectralPreprocessingOptions preprocessOptions
			)
		{
			IMatrix matrixX, matrixY;
			IROVector xOfX;
			var plsContent = new MultivariateContentMemento();
			plsContent.Analysis = this;

			// 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
			string newName = this.AnalysisName + " of " + Main.ProjectFolder.GetNamePart(srctable.Name);
			newName = Main.ProjectFolder.CreateFullName(srctable.Name, newName);
			Altaxo.Data.DataTable table = new Altaxo.Data.DataTable(newName);
			// Fill the Table
			using (var suspendToken = table.SuspendGetToken())
			{
				table.SetTableProperty("Content", plsContent);
				plsContent.OriginalDataTableName = srctable.Name;

				// Get matrices
				GetXYMatrices(
					srctable,
					selectedColumns,
					selectedRows,
					selectedPropertyColumns,
					bHorizontalOrientedSpectrum,
					plsContent,
					out matrixX, out matrixY, out xOfX);

				StoreXOfX(xOfX, table);

				// Preprocess
				plsContent.SpectralPreprocessing = preprocessOptions;
				IVector meanX, scaleX, meanY, scaleY;
				MultivariateRegression.PreprocessForAnalysis(preprocessOptions, xOfX, matrixX, matrixY,
					out meanX, out scaleX, out meanY, out scaleY);

				StorePreprocessedData(meanX, scaleX, meanY, scaleY, table);

				// Analyze and Store
				IROVector press;
				ExecuteAnalysis(
					matrixX,
					matrixY,
					plsOptions,
					plsContent,
					table, out press);

				this.StorePRESSData(press, table);

				if (plsOptions.CrossPRESSCalculation != CrossPRESSCalculationType.None)
					CalculateCrossPRESS(xOfX, matrixX, matrixY, plsOptions, plsContent, table);

				StoreFRatioData(table, plsContent);

				StoreOriginalY(table, plsContent);

				suspendToken.Dispose();
			}
			Current.Project.DataTableCollection.Add(table);
			// create a new worksheet without any columns
			Current.ProjectService.CreateNewWorksheet(table);

			return null;
		}
开发者ID:Altaxo,项目名称:Altaxo,代码行数:86,代码来源:WorksheetAnalysis.cs

示例2: MultiplyColumnsToMatrix

		/// <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);
			using (var suspendToken = table.SuspendGetToken())
			{
				// 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());
				}
				suspendToken.Dispose();
			}

			mainDocument.DataTableCollection.Add(table);
			// create a new worksheet without any columns
			Current.ProjectService.CreateNewWorksheet(table);

			return null;
		}
开发者ID:Altaxo,项目名称:Altaxo,代码行数:100,代码来源:ChemometricCommands.cs

示例3: TransferTemporaryTable

		/// <summary>
		/// Transfers a temporary table to a destination table. The first data columns and property columns of the destination table are replaced by the columns of the temporary table. The source table is destoyed during the transfer process (in order to save memory).
		/// </summary>
		/// <param name="fromSourceTable">Source table. Is destroyed during the transfer operation.</param>
		/// <param name="toDestinationTable">Destination table.</param>
		private static void TransferTemporaryTable(DataTable fromSourceTable, DataTable toDestinationTable)
		{
			using (var suspendToken = toDestinationTable.SuspendGetToken())
			{
				// data columns first
				var srcCollection = fromSourceTable.DataColumns;
				var destCollection = toDestinationTable.DataColumns;
				for (int i = 0; i < srcCollection.ColumnCount; ++i)
				{
					var srcColumn = srcCollection[i];
					var destColumn = destCollection.EnsureExistenceAtPositionStrictly(i, srcCollection.GetColumnName(srcColumn), srcColumn.GetType(), srcCollection.GetColumnKind(srcColumn), srcCollection.GetColumnGroup(srcColumn));
					destColumn.Clear();
					destColumn.CopyDataFrom(srcColumn);
					srcColumn.Clear();
				}

				// then property columns
				srcCollection = fromSourceTable.PropCols;
				destCollection = toDestinationTable.PropCols;
				for (int i = 0; i < srcCollection.ColumnCount; ++i)
				{
					var srcColumn = srcCollection[i];
					var destColumn = destCollection.EnsureExistenceAtPositionStrictly(i, srcCollection.GetColumnName(srcColumn), srcColumn.GetType(), srcCollection.GetColumnKind(srcColumn), srcCollection.GetColumnGroup(srcColumn));
					destColumn.Clear();
					destColumn.CopyDataFrom(srcColumn);
					srcColumn.Clear();
				}

				suspendToken.Dispose();
			}
		}
开发者ID:Altaxo,项目名称:Altaxo,代码行数:36,代码来源:AsciiImporter.cs

示例4: PrincipalComponentAnalysis


//.........这里部分代码省略.........
						++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
			using (var suspendToken = table.SuspendGetToken())
			{
				// 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);
				}

				suspendToken.Dispose();
			}

			mainDocument.DataTableCollection.Add(table);
			// create a new worksheet without any columns
			Current.ProjectService.CreateNewWorksheet(table);

			return null;
		}
开发者ID:Altaxo,项目名称:Altaxo,代码行数:101,代码来源:ChemometricCommands.cs


注:本文中的Altaxo.Data.DataTable.SuspendGetToken方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。