本文整理汇总了C#中DotNetMatrix.GeneralMatrix.SetElement方法的典型用法代码示例。如果您正苦于以下问题:C# GeneralMatrix.SetElement方法的具体用法?C# GeneralMatrix.SetElement怎么用?C# GeneralMatrix.SetElement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DotNetMatrix.GeneralMatrix
的用法示例。
在下文中一共展示了GeneralMatrix.SetElement方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CalculateHessian
public GeneralMatrix CalculateHessian(double[]x)
{
GeneralMatrix hessian = new GeneralMatrix(Dimension,Dimension);
for (int i=0; i<Dimension; i++)
for (int j=0; j<Dimension; j++)
hessian.SetElement(i,j,GetPartialDerivativeVal(i,j,x));
return hessian;
}
示例2: LUDecomposition
public void LUDecomposition()
{
GeneralMatrix A = new GeneralMatrix(columnwise, 4);
int n = A.ColumnDimension;
A = A.GetMatrix(0, n - 1, 0, n - 1);
A.SetElement(0, 0, 0.0);
LUDecomposition LU = A.LUD();
Assert.IsTrue(GeneralTests.Check(A.GetMatrix(LU.Pivot, 0, n - 1), LU.L.Multiply(LU.U)));
}
示例3: Main
//.........这里部分代码省略.........
}
}
catch (System.ArgumentException e1)
{
errorCount = try_failure(errorCount, "GetMatrix(int[],int[])... ", "ArrayIndexOutOfBoundsException expected but not thrown");
System.Console.Out.WriteLine(e1.Message);
}
try
{
M = B.GetMatrix(rowindexset, columnindexset);
try
{
check(SUB, M);
try_success("GetMatrix(int[],int[])... ", "");
}
catch (System.SystemException e)
{
errorCount = try_failure(errorCount, "GetMatrix(int[],int[])... ", "submatrix not successfully retreived");
System.Console.Out.WriteLine(e.Message);
}
}
catch (System.IndexOutOfRangeException e)
{
errorCount = try_failure(errorCount, "GetMatrix(int[],int[])... ", "Unexpected ArrayIndexOutOfBoundsException");
System.Console.Out.WriteLine(e.Message);
}
/// <summary>Various set methods:
///
/// </summary>
try
{
B.SetElement(B.RowDimension, B.ColumnDimension - 1, 0.0);
errorCount = try_failure(errorCount, "set(int,int,double)... ", "OutOfBoundsException expected but not thrown");
}
catch (System.IndexOutOfRangeException e)
{
System.Console.Out.WriteLine(e.Message);
try
{
B.SetElement(B.RowDimension - 1, B.ColumnDimension, 0.0);
errorCount = try_failure(errorCount, "set(int,int,double)... ", "OutOfBoundsException expected but not thrown");
}
catch (System.IndexOutOfRangeException e1)
{
try_success("set(int,int,double)... OutofBoundsException... ", "");
System.Console.Out.WriteLine(e1.Message);
}
}
catch (System.ArgumentException e1)
{
errorCount = try_failure(errorCount, "set(int,int,double)... ", "OutOfBoundsException expected but not thrown");
System.Console.Out.WriteLine(e1.Message);
}
try
{
B.SetElement(ib, jb, 0.0);
tmp = B.GetElement(ib, jb);
try
{
check(tmp, 0.0);
try_success("set(int,int,double)... ", "");
}
catch (System.SystemException e)
{
示例4: computeaccCalButton_Click
private void computeaccCalButton_Click(object sender, EventArgs e)
{
int i,j;
calStatusText.Text = "Computing Calibration...";
// Construct D matrix
// D = [x.^2, y.^2, z.^2, x.*y, x.*z, y.*z, x, y, z, ones(N,1)];
for (i = 0; i < SAMPLES; i++ )
{
// x^2 term
D.SetElement(i,0, loggedData[i,0]*loggedData[i,0]);
// y^2 term
D.SetElement(i,1,loggedData[i,1]*loggedData[i,1]);
// z^2 term
D.SetElement(i, 2, loggedData[i, 2] * loggedData[i, 2]);
// x*y term
D.SetElement(i,3,loggedData[i,0]*loggedData[i,1]);
// x*z term
D.SetElement(i,4,loggedData[i,0]*loggedData[i,2]);
// y*z term
D.SetElement(i,5,loggedData[i,1]*loggedData[i,2]);
// x term
D.SetElement(i,6,loggedData[i,0]);
// y term
D.SetElement(i,7,loggedData[i,1]);
// z term
D.SetElement(i,8,loggedData[i,2]);
// Constant term
D.SetElement(i,9,1);
}
// QR=triu(qr(D))
QRDecomposition QR = new QRDecomposition(D);
// [U,S,V] = svd(D)
SingularValueDecomposition SVD = new SingularValueDecomposition(QR.R);
GeneralMatrix V = SVD.GetV();
GeneralMatrix A = new GeneralMatrix(3, 3);
double[] p = new double[V.RowDimension];
for (i = 0; i < V.RowDimension; i++ )
{
p[i] = V.GetElement(i,V.ColumnDimension-1);
}
/*
A = [p(1) p(4)/2 p(5)/2;
p(4)/2 p(2) p(6)/2;
p(5)/2 p(6)/2 p(3)];
*/
if (p[0] < 0)
{
for (i = 0; i < V.RowDimension; i++)
{
p[i] = -p[i];
}
}
A.SetElement(0,0,p[0]);
A.SetElement(0,1,p[3]/2);
A.SetElement(1,2,p[4]/2);
A.SetElement(1,0,p[3]/2);
A.SetElement(1,1,p[1]);
A.SetElement(1,2,p[5]/2);
A.SetElement(2,0,p[4]/2);
A.SetElement(2,1,p[5]/2);
A.SetElement(2,2,p[2]);
CholeskyDecomposition Chol = new CholeskyDecomposition(A);
GeneralMatrix Ut = Chol.GetL();
GeneralMatrix U = Ut.Transpose();
double[] bvect = {p[6]/2,p[7]/2,p[8]/2};
double d = p[9];
GeneralMatrix b = new GeneralMatrix(bvect,3);
GeneralMatrix v = Ut.Solve(b);
double vnorm_sqrd = v.GetElement(0,0)*v.GetElement(0,0) + v.GetElement(1,0)*v.GetElement(1,0) + v.GetElement(2,0)*v.GetElement(2,0);
double s = 1/Math.Sqrt(vnorm_sqrd - d);
GeneralMatrix c = U.Solve(v);
for (i = 0; i < 3; i++)
{
c.SetElement(i, 0, -c.GetElement(i, 0));
}
//.........这里部分代码省略.........
示例5: TestTranspose
public void TestTranspose()
{
GeneralMatrix _gm = new GeneralMatrix(2,2);
_gm.SetElement(0,0,1);
_gm.SetElement(0,1,2);
_gm.SetElement(1,0,3);
_gm.SetElement(1,1,4);
GeneralMatrix _ngm = _gm.Transpose();
Assert.AreEqual(1,0,2);
}
示例6: TestSolve
public void TestSolve()
{
GeneralMatrix _ls = new GeneralMatrix(2,2);
_ls.SetElement(0,0,1);
_ls.SetElement(0,1,2);
_ls.SetElement(1,0,3);
_ls.SetElement(1,1,4);
GeneralMatrix _rs = new GeneralMatrix(2,1);
_rs.SetElement(0,0,-3);
_rs.SetElement(1,0,-5);
GeneralMatrix _solution = _ls.Solve(_rs);
Assert.AreEqual(_solution.GetElement(0,0),1);
Assert.AreEqual(_solution.GetElement(1,0),-2);
}
示例7: TestNorm1
public void TestNorm1()
{
GeneralMatrix _gm = new GeneralMatrix(2,2);
_gm.SetElement(0,0,1);
_gm.SetElement(0,1,2);
_gm.SetElement(1,0,3);
_gm.SetElement(1,1,4);
Assert.AreEqual(6,_gm.Norm1());
}
示例8: PCalc
/// <summary>
/// Average values of the priority matrix over sum of columns.
/// set values of sum of averaged rows into a new matrix
/// </summary>
/// <param name="argMatrix"></param>
/// <param name="selection"></param>
public void PCalc(GeneralMatrix argMatrix, GeneralMatrix selection)
{
int n = argMatrix.ColumnDimension;
GeneralMatrix sMatrix = new GeneralMatrix(argMatrix.ArrayCopy);
double c=0.0;
int i,j;
for (i=0;i<sMatrix.ColumnDimension; i++)
{
c=0.0;
for (j=0; j<sMatrix.RowDimension; j++)
c+=sMatrix.GetElement(j,i);
selection.SetElement(i,0,c);
}
for (i=0;i<sMatrix.ColumnDimension; i++)
{
for (j=0; j<sMatrix.RowDimension; j++)
sMatrix.SetElement(j,i,sMatrix.GetElement(j,i)/selection.GetElement(i,0));
}
for (i=0;i<sMatrix.RowDimension; i++)
{
c=0.0;
for (j=0; j<sMatrix.ColumnDimension; j++)
c+=sMatrix.GetElement(i,j);
selection.SetElement(i,0,c/n);
}
}
示例9: SetElementWithInvalidRowIndexThrowsAnException
public void SetElementWithInvalidRowIndexThrowsAnException()
{
var matrix = new GeneralMatrix(avals);
matrix.SetElement(matrix.RowDimension,matrix.ColumnDimension + 1, 0.0);
}
示例10: SetElementCorrectlySetsAMatrixElement
public void SetElementCorrectlySetsAMatrixElement()
{
var matrix = new GeneralMatrix(avals);
matrix.SetElement(ib,jb,0.0);
Assert.AreEqual(0.0,matrix.GetElement(ib,jb));
}
示例11: makeDiagonalSquare
private static GeneralMatrix makeDiagonalSquare(double[] m, int cols)
{
GeneralMatrix result = new GeneralMatrix(cols, cols);
for (int j = 0; j < cols; j++)
{
for (int i = 0; i < cols; i++)
{
if (j == i)
{
result.SetElement(i, j, m[i]);
}
else
{
result.SetElement(i, j, 0);
}
}
}
return result;
}
示例12: GetFiles_Decompose_WriteToArff
private void GetFiles_Decompose_WriteToArff()
{
try {
// sampleFactor is the amount to divide by the total size of the
// data set
// when determining the subsample that will be used in svd
Console.WriteLine("Creating arff file...");
DisplayMessage("Creating arff file...");
// Create folder
System.IO.Directory.CreateDirectory(OutputDir + "Results/");
StreamWriter output = new StreamWriter(OutputDir + "Results/" + "resultsGalaxy.arff");
output.Write("@relation 'galaxy'\n");
output.Write("@attribute class real\n");
output.Write("@attribute colorF real\n");
output.Write("@attribute bulgeF real\n");
output.Write("@attribute constF real\n");
for (int i = 0; i < sv * 3; i++) {
output.Write("@attribute " + i + " real\n");
}
output.Write("@data\n");
Console.WriteLine("Begin galaxy sampling");
DisplayMessage("Begin galaxy sampling");
// Initialize a three matrices that will hold all of the images
// (r,g,b of each image where each row is an image)
dataRed = new GeneralMatrix(galaxyData.Count() / sampleFactor,
imageScaleSize * imageScaleSize);
dataGreen = new GeneralMatrix(galaxyData.Count() / sampleFactor,
imageScaleSize * imageScaleSize);
dataBlue = new GeneralMatrix(galaxyData.Count() / sampleFactor,
imageScaleSize * imageScaleSize);
// subsample from galaxydata
System.Threading.Tasks.Parallel.For(0, galaxyData.Count() / sampleFactor, (int index) => {
Bitmap tempImage = getImage(OutputDir + "galaxies/"
+ galaxyData[sampleFactor * index][0] + ".jpg", imageScaleSize);
for (int i = 0; i < imageScaleSize; i++) {
for (int j = 0; j < imageScaleSize; j++) {
int pixelColor = tempImage.GetPixel(i, j).ToArgb();
int[] rgb = new int[3];
rgb[0] += ((pixelColor & 0x00ff0000) >> 16);
rgb[1] += ((pixelColor & 0x0000ff00) >> 8);
rgb[2] += (pixelColor & 0x000000ff);
dataRed.SetElement(index, i * imageScaleSize + j, rgb[0]);
dataGreen.SetElement(index, i * imageScaleSize + j, rgb[1]);
dataBlue.SetElement(index, i * imageScaleSize + j, rgb[2]);
}
}
//if (index % 10 == 0)
//DisplayImage(index);
//Console.WriteLine("Galaxy " + (sampleFactor * index) + " finished");
});
Console.WriteLine("Galaxy sampling finished\nBegin R, G and B channel SVD");
DisplayMessage("Galaxy sampling finished, Begin R, G and B channel SVD");
// Perform svd on subsample:
var redWorker = System.Threading.Tasks.Task.Factory.StartNew(() => svdR = new SingularValueDecomposition(dataRed));
var greenWorker = System.Threading.Tasks.Task.Factory.StartNew(() => svdG = new SingularValueDecomposition(dataGreen));
var blueWorker = System.Threading.Tasks.Task.Factory.StartNew(() => svdB = new SingularValueDecomposition(dataBlue));
System.Threading.Tasks.Task.WaitAll(redWorker, greenWorker, blueWorker);
// Create the basis for each component
GeneralMatrix rV = svdR.GetV();
Console.Write("dim rU: " + rV.RowDimension + ", "
+ rV.ColumnDimension);
GeneralMatrix gV = svdG.GetV();
GeneralMatrix bV = svdB.GetV();
rV = GetSVs(rV, sv);
Console.Write("Svs: " + sv);
Console.Write("Dim SsV: " + rV.RowDimension + ", "
+ rV.ColumnDimension);
gV = GetSVs(gV, sv);
bV = GetSVs(bV, sv);
// Perform the pseudoinverses
frV = pinv(rV.Transpose());
fgV = pinv(gV.Transpose());
fbV = pinv(bV.Transpose());
// Stores frV, fgV and fbV to file
WriteToFile();
Console.WriteLine("SVD finished");
DisplayMessage("SVD finished, load full dataset for testing");
Console.WriteLine("Begin filling dataset for testing");
// fill the 'full' datasets
dataRed = new GeneralMatrix(galaxyData.Count(), imageScaleSize
* imageScaleSize);
dataGreen = new GeneralMatrix(galaxyData.Count(), imageScaleSize
//.........这里部分代码省略.........
示例13: ClassifyGroup
private void ClassifyGroup(string[] images, string filePath, StreamWriter output, int groupNum)
{
// fill the 'full' datasets
dataRed = new GeneralMatrix(images.Count(), imageScaleSize
* imageScaleSize);
dataGreen = new GeneralMatrix(images.Count(), imageScaleSize
* imageScaleSize);
dataBlue = new GeneralMatrix(images.Count(), imageScaleSize
* imageScaleSize);
//create the entire size of the dataset
System.Threading.Tasks.Parallel.For(0, images.Count(), (int imageIndex) => {
Bitmap tempImage = getImage(images[imageIndex], imageScaleSize);
for (int i = 0; i < imageScaleSize; i++) {
for (int j = 0; j < imageScaleSize; j++) {
int pixelColor = tempImage.GetPixel(i, j).ToArgb();
int[] rgb = new int[3];
rgb[0] += ((pixelColor & 0x00ff0000) >> 16);
rgb[1] += ((pixelColor & 0x0000ff00) >> 8);
rgb[2] += (pixelColor & 0x000000ff);
dataRed.SetElement(imageIndex, i * imageScaleSize + j, rgb[0]);
dataGreen.SetElement(imageIndex, i * imageScaleSize + j,
rgb[1]);
dataBlue.SetElement(imageIndex, i * imageScaleSize + j, rgb[2]);
}
}
Console.WriteLine("SDSS Galaxy " + imageIndex + " put in main dataset");
});
//then convert the whole dataset to the same coordinate
// Do the coordinate conversion
GeneralMatrix rV = dataRed.Multiply(frV);
GeneralMatrix gV = dataGreen.Multiply(fgV);
GeneralMatrix bV = dataBlue.Multiply(fbV);
Console.WriteLine("Dim Final rU: " + rV.ColumnDimension
+ ", " + rV.RowDimension);
Console.WriteLine("images.length: " + images.Count());
// write to the output file here:
for (int imageIndex = 0; imageIndex < images.Count(); imageIndex++) {
Bitmap tempImage = getImage(images[imageIndex], imageScaleSize);
float colorFactor = (GetColor(tempImage)[0] / GetColor(tempImage)[2]);
float centralBulgeFactor = getCentralBulge(tempImage);
float consistencyFactor = GetConsistency(tempImage);
output.Write(-999 + ", ");
output.Write(colorFactor + ", ");
output.Write(centralBulgeFactor + ", ");
output.Write(consistencyFactor + ", ");
// output data (r,g,b)
for (int i = 0; i < rV.ColumnDimension; i++) {
output.Write(rV.GetElement(imageIndex, i) + ", ");
output.Write(gV.GetElement(imageIndex, i) + ", ");
if (i == rV.ColumnDimension - 1) {
output.Write(bV.GetElement(imageIndex, i) + "\n");
}
else {
output.Write(bV.GetElement(imageIndex, i) + ", ");
}
}
Console.WriteLine("Creating ARFF classification file - " + (100 * imageIndex / images.Count()).ToString() + "%");
}
}
示例14: GetSVs
// Take SV columns from the U matrix
private static GeneralMatrix GetSVs(GeneralMatrix matrix, int sv)
{
GeneralMatrix toPass = new GeneralMatrix(matrix.RowDimension, sv);
for (int j = 0; j < sv; j++) {
for (int i = 0; i < matrix.RowDimension; i++) {
toPass.SetElement(i, j, matrix.GetElement(i, j));
}
}
return toPass;
}
示例15: calculateR
private double[][] calculateR()
{
sourceCount = sourceASTL.abstractLatticeGraph.VertexCount;
targetCount = targetASTL.abstractLatticeGraph.VertexCount;
GeneralMatrix newR = new GeneralMatrix(sourceCount * targetCount, 1);
GeneralMatrix myA = new GeneralMatrix(A);
//initial R
for (int i = 0; i < newR.RowDimension; i++)
{
newR.SetElement(i, 0, 1.0 / newR.RowDimension);
}
//printMatrix(vector2Matrix(newR.Array, 0));
//move similarity matrix to a double index vector
GeneralMatrix newSim = new GeneralMatrix(sourceCount * targetCount, 1);
for (int i = 0; i < sourceCount; i++)
for (int j = 0; j < targetCount; j++)
{
newSim.SetElement(targetCount * i + j, 0, simMatrix[i, j]);
}
//move structure similarity matrix to a double index vector
GeneralMatrix newStructSim = new GeneralMatrix(sourceCount * targetCount, 1);
//for (int i = 0; i < sourceCount; i++)
// for (int j = 0; j < targetCount; j++)
// {
// newStructSim.SetElement(targetCount * i + j, 0, structSimMatrix[i, j]);
// }
//calculate R using power method (eigen vector)
//==========================================
int count = 0;
while (count < 50)
{
//R = aAR + (1-2a)E1 + (1-2a)E2 where a = 0.333
//newR = (((myA.Multiply(newR)).Multiply(0.333)).Add(newStructSim.Multiply(0.333))).Add(newSim.Multiply(0.333));//ommited to have name similarity only 17/4/2012
newR = (((myA.Multiply(newR)).Multiply(0.5)).Add(newSim.Multiply(0.5)));
double sum = 0;
for (int i = 0; i < newR.RowDimension; i++)
for (int j = 0; j < newR.ColumnDimension; j++)
sum += newR.GetElement(i, j);
newR = newR.Multiply(1.0 / sum);
count++;
}
return newR.Array;
}