//work in progress
//NeuralNetwork.java
package com.smkltd.app;
import java.util.Random;
import Jama.Matrix;
import Jama.EigenvalueDecomposition;
public class NeuralNetwork
{
int V;
int E;
Matrix EdgeWeight;
Matrix VertexWeight;
Matrix Threshold;
Matrix Inhomogeneous;
Matrix CurrentState;
Matrix dZdt;
Matrix A;
Matrix VarCov;
Matrix EZZT;
Matrix dEZZTdt;
Matrix sysmat;
TwoBit Incidence;
public NeuralNetwork(int nrows, int ncols) {
this.V = nrows;
this.E = ncols;
this.EdgeWeight = new Matrix(new double[1][ncols]);
this.VertexWeight = new Matrix(new double[nrows][1]);
this.Threshold = new Matrix(new double[nrows][1]);
this.Inhomogeneous = new Matrix(new double[nrows][1]);
this.CurrentState = new Matrix(new double[nrows][1]);
this.dZdt = new Matrix(new double[nrows][1]);
this.EZZT.identity(nrows,nrows);
this.dEZZTdt = new Matrix(new double[nrows][nrows]);
this.Incidence = new TwoBit(nrows,ncols);
this.sysmat = new Matrix(new double[nrows][nrows]);
}
public void rk4LDE1(double step)
{
double hh = 0.5*step;
double h6 = step/6;
Matrix dZm = new Matrix(new double[V][1]);
Matrix dZt = new Matrix(new double[V][1]);
Matrix Zt = new Matrix(new double[V][1]);
dZdt = sysmat.times(CurrentState).plus(Inhomogeneous);
Zt = CurrentState.plus(dZdt.times(hh));
dZt = sysmat.times(Zt).plus(Inhomogeneous);
Zt = CurrentState.plus(dZt.times(hh));
dZm = sysmat.times(Zt).plus(Inhomogeneous);
Zt = CurrentState.plus(dZm.times(step));
dZm = dZm.plus(dZt);
dZt = sysmat.times(Zt).plus(Inhomogeneous);
CurrentState = CurrentState.plus(dZdt.plus(dZt).plus(dZm.times(2.0)).times(h6));
}
public void rk4LDE1cov(double step)
{
double hh = 0.5*step;
double h6 = step/6;
Matrix dZm = new Matrix(new double[V][V]);
Matrix dZt = new Matrix(new double[V][V]);
Matrix Zt = new Matrix(new double[V][V]);
dEZZTdt = sysmat.times(EZZT).plus(EZZT.times(sysmat.transpose())).plus(VarCov);
Zt = EZZT.plus(dEZZTdt.times(hh));
dZt = sysmat.times(Zt).plus(Zt.times(sysmat.transpose())).plus(VarCov);
Zt = EZZT.plus(dZt.times(hh));
dZm = sysmat.times(Zt).plus(Zt.times(sysmat.transpose())).plus(VarCov);
Zt = EZZT.plus(dZm.times(step));
dZm = dZm.plus(dZt);
dZt = sysmat.times(Zt).plus(Zt.times(sysmat.transpose())).plus(VarCov);
EZZT = EZZT.plus(dEZZTdt.plus(dZt).plus(dZm.times(2.0)).times(h6));
}
public void lyapunovEq()
{
// oh well N = sysmat is singular so that N and NT share 0 as common eigenvalue
// so that MyKron is singular also isf there is to be a solution vecQ = vec(VarCov)
// must be a linear combination of the columns of MyKron (then deVectorize)
// NX + XNT = 0 has soln Xnull so that any soln would be c*Xnull + particular
// looks like you need schur decomp and Strsyl from LAPACK to solve non singular case
// efficiently without kron products and vec
int dimv = V*V;
Matrix vecQ = new Matrix(new double[dimv][1]);
Matrix MyKron = new Matrix(new double[dimv][dimv]);
int kk;
int ll;
for (int ii=0; ii<V; ii++)
{
for (int jj=0; jj<V; jj++)
{
kk=V*ii+jj;
vecQ.set(kk,0,-VarCov.get(ii,jj));
for (int iii=0; iii<V; iii++)
{
for (int jjj=0; jjj<V; jjj++)
{
ll=V*iii+jjj;
if ((ii==iii)&(jj==jjj)){
MyKron.set(kk,ll,sysmat.get(ii,iii));
} else if ((jj==jjj)&(ii!=iii)) {
MyKron.set(kk,ll,sysmat.get(ii,iii));
}
}
}
for (int iii=0; iii<V; iii++)
{
for (int jjj=0; jjj<V; jjj++)
{
ll=V*iii+jjj;
if ((jj==jjj)&(ii==iii)){
MyKron.set(kk,ll,MyKron.get(kk,ll)+sysmat.get(jj,jjj));
} else if ((ii==iii)&(jj!=jjj)) {
MyKron.set(kk,ll,MyKron.get(kk,ll)+sysmat.get(jj,jjj));
}
}
}
}
}
Matrix vecX = MyKron.getMatrix(0,dimv-2,0,dimv-2).solve(vecQ.getMatrix(0,dimv-2,0,0));
System.out.println(" MyKron rank = "+MyKron.rank());
Matrix devecX = new Matrix(new double[V][V]);
int r;
int c;
for (int ii=0; ii<dimv-1; ii++)
{
c = ii%V;
r = (ii-c)/V;
devecX.set(r,c,vecX.get(ii,0));
}
System.out.println(" Printing covariance matrix <DZ.DZT>particular for MyNeuralNetwork.lyapunovEq()");
System.out.println(" Null matrix <DZ.DZT> for MyNeuralNetwork.lyapunovEq() is square matrix of 1's");
System.out.println(" Equilibrium points are const*null + particular");
devecX.print(7,4);
System.out.println(" Checking ");
System.out.println(" sysmat.times(particular).plus(particular.times(sysmat.transpose())).times(-1)");
sysmat.times(devecX).plus(devecX.times(sysmat.transpose())).times(-1).print(7,4);
}
private Matrix Gram(Matrix m1, boolean type)
{
Matrix m3;
if (type) {
m3 = new Matrix(new double[m1.getRowDimension()][m1.getRowDimension()]);
m3 = m1.times(m1.transpose());
} else {
m3 = new Matrix(new double[m1.getColumnDimension()][m1.getColumnDimension()]);
m3 = m1.transpose().times(m1);
}
return m3;
}
public void VarCov(Matrix MyA, Matrix MyB)
{
A = MyA; //this correlates the gaussian white noise dW/dt
VarCov = Gram(sysmat.times(MyA), true);
EZZT = Gram(MyB, true);
}
private double StepFunction(double arg, double a, double b)
{
double sf;
if (arg>0) {
sf = a;
} else if (arg == 0) {
sf = (a+b)/2;
} else {
sf = b;
}
return sf;
}
public void Hop()
{
Matrix nextState = CurrentState;
for (int ii=0; ii<V; ii++)
{
nextState.set(ii,0,StepFunction(Incidence.PKQTC.times(CurrentState).minus(Threshold).get(ii,0),1.0,-1.0));
}
CurrentState=nextState;
}
public void SysMat(double Dt)
{
for (int ii=0; ii<V; ii++)
{
for (int jj=0; jj<V; jj++)
{
if (ii==jj) {
sysmat.set(ii,jj,Incidence.PKQTC.get(ii,jj) - 1);
} else {
sysmat.set(ii,jj,Incidence.PKQTC.get(ii,jj));
}
}
}
sysmat=sysmat.times(1/Dt);
}
public Matrix Kron(Matrix A, Matrix B)
{
int rr;
int cc;
int mm = A.getRowDimension();
int nn = A.getColumnDimension();
int pp = B.getRowDimension();
int qq = B.getColumnDimension();
Matrix myKron = new Matrix(new double[mm*pp][nn*qq]);
for (int ii=0; ii<mm; ii++)
{
for (int jj=0; jj<nn; jj++)
{
for (int kk=0; kk<pp; kk++)
{
for (int ll=0; ll<qq; ll++)
{
rr = ii*pp+kk;
cc = jj*qq+ll;
myKron.set(rr,cc,A.get(ii,jj)*B.get(kk,ll));
}
}
}
}
return myKron;
}
public Matrix Vec(Matrix A)
{
int rd = A.getRowDimension();
int cd = A.getColumnDimension();
int kk = -1;
Matrix vecA = new Matrix(new double[rd*cd][1]);
for (int jj=0; jj<cd; jj++)
{
for (int ii=0; ii<rd; ii++)
{
kk++;
vecA.set(kk,0,A.get(ii,jj));
}
}
return vecA;
}
public Matrix deVec(Matrix vA, int rd, int cd)
{
Matrix dvA = new Matrix(new double[rd][cd]);
int ii;
int jj;
for (int kk = 0; kk<Math.min(rd*cd,vA.getRowDimension()); kk++)
{
ii=kk%rd;
jj=(kk-ii)/rd;
dvA.set(ii,jj,vA.get(kk,0));
}
return dvA;
}
public static void main( String[] args )
{
System.out.println(" ");
int[][] MyIncidence = new int[][] {
{1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{-1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, -1, 0, -1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, -1, 0, -1, 0, -1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, -1, 0, -1, 0, -1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, -1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, -1, 0, 0, 0, -1, 0, 1, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, -1, 0, 1, 1, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, -1, -1, 0, 1},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, -1, -1}
};
Matrix MyEW = new Matrix(new double[][] {{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}}); // Synapse Weight
Matrix MyVW = new Matrix(new double[][] {{1,1,1,1,1,1,1,1,1,1}}); // Neuron Weight
MyVW = MyVW.transpose();
Matrix MyVT = new Matrix(new double[][] {{0,0,0,0,0,0,0,0,0,0}}); // Neuron Threshold;
MyVT = MyVT.transpose();
Matrix MyInitState = new Matrix(new double[][] {{-1,-1,1,-1,1,1,1,-1,-1,1}});
MyInitState = MyInitState.transpose();
Random fRandom = new Random();
Matrix MyA = new Matrix(new double[MyIncidence.length][MyIncidence.length]);
Matrix MyB = new Matrix(new double[MyIncidence.length][MyIncidence.length]);
for (int row = 0; row < MyIncidence.length; row++)
{
for (int col = 0; col < MyIncidence.length; col++)
{
MyA.set(row,col,fRandom.nextGaussian());
}
}
NeuralNetwork MyNeuralNetwork = new NeuralNetwork(MyIncidence.length,MyIncidence[0].length);
for (int row = 0; row < MyNeuralNetwork.V; row++)
{
for (int col = 0; col < MyNeuralNetwork.E; col++)
{
MyNeuralNetwork.Incidence.Set(row,col,MyIncidence[row][col]);
}
}
MyNeuralNetwork.EdgeWeight = MyEW;
MyNeuralNetwork.VertexWeight = MyVW;
MyNeuralNetwork.Threshold = MyVT;
MyNeuralNetwork.CurrentState = MyInitState.copy();
boolean normalized = true;
MyNeuralNetwork.Incidence.Adjacency(MyNeuralNetwork.EdgeWeight, MyNeuralNetwork.VertexWeight, normalized);
MyNeuralNetwork.SysMat(1.0);
MyB = MyB.identity(MyNeuralNetwork.V, MyNeuralNetwork.V);
MyNeuralNetwork.VarCov(MyA,MyB); //right here made covariance of dW singular NA.ATNT making lyapunov solution possible
System.out.println(" ");
System.out.println(" A couple of Hops: CurrentState.transpose()");
MyNeuralNetwork.CurrentState.transpose().print(6,4);
int jj = 0;
while (jj < 10)
{
MyNeuralNetwork.Hop();
MyNeuralNetwork.CurrentState.transpose().print(6,4);
jj++;
}
System.out.println(" ..................");
System.out.println(" Coupled Langevin Equations with corrrelated Gaussian white noise");
System.out.println(" Continuous time model expected value of neuron CurrentState.transpose()");
System.out.println(" dZ = N(Zdt + AdW)");
int ii = 0;
int nn = 26;
double step =.05;
double ndz = 1.0;
MyNeuralNetwork.CurrentState = MyInitState.copy();
MyNeuralNetwork.CurrentState.transpose().print(6,4);
while ((ii < 10000)&(ndz>.000001))
{
MyNeuralNetwork.rk4LDE1(step);
MyNeuralNetwork.rk4LDE1cov(step);
if (ii<nn) {
MyNeuralNetwork.CurrentState.transpose().print(6,4);
}
if (ii==nn) {
System.out.println(" .................. iter = "+nn);
}
if (ndz<.0000015) {
MyNeuralNetwork.CurrentState.transpose().print(6,4);
}
ii++;
ndz = MyNeuralNetwork.dZdt.normF();
}
System.out.println(" .................. iter = "+ii);
System.out.println(" ");
System.out.println(" ");
ndz = 100;
ii=0;
while ((ii < 10000)&(ndz> 0.000000001))
{
MyNeuralNetwork.rk4LDE1cov(step);
ii++;
ndz = MyNeuralNetwork.dEZZTdt.normF();
}
System.out.println(" Printing row normalized PKQTC for MyNeuralNetwork");
MyNeuralNetwork.Incidence.PKQTC.print(7,4);
System.out.println(" Printing N = sysmat for MyNeuralNetwork");
MyNeuralNetwork.sysmat.print(7,4);
System.out.println(" Printing Gaussian white noise covariance matrix A.AT for MyNeuralNetwork");
MyNeuralNetwork.Gram(MyNeuralNetwork.A,true).print(7,4);
System.out.println(" determinant = "+MyNeuralNetwork.Gram(MyNeuralNetwork.A,true).det());
System.out.println(" condition = "+MyNeuralNetwork.Gram(MyNeuralNetwork.A,true).cond());
System.out.println(" ");
System.out.println(" Printing covariance matrix NA.ATNT for MyNeuralNetwork iter = "+ii);
MyNeuralNetwork.VarCov.print(7,4);
System.out.println(" Printing covariance matrix <DZ.DZT> for MyNeuralNetwork iter = "+ii);
System.out.println(" Initial covariance matrix <DZ0.DZ0T> assumed to be identity matrix");
MyNeuralNetwork.EZZT.print(7,4);
System.out.printf(" N<DZ.DZT> + <DZ.DZT>NT + NA.ATNT = "+String.format(" %,.8f ", MyNeuralNetwork.dEZZTdt.normF()));
System.out.println(" ");
System.out.println(" determinant = "+MyNeuralNetwork.EZZT.det());
System.out.println(" condition = "+MyNeuralNetwork.EZZT.cond());
System.out.println(" ");
MyNeuralNetwork.lyapunovEq();
//checking fudgy KronProd code in lyapunovEq() to more systematic Kron, Vec, and deVec function
//had stacked rows in lyapunovEq(), Vec() stacks columns with Kron() consistent with that convention
//int V = MyNeuralNetwork.V;
//int dimv = V*V;
//next 2 line double checking the lyapunovEq() function
//MyNeuralNetwork.deVec(MyNeuralNetwork.Kron(MyB,MyNeuralNetwork.sysmat).plus(MyNeuralNetwork.Kron(MyNeuralNetwork.sysmat,MyB))
// .getMatrix(0,dimv-2,0,dimv-2).solve(MyNeuralNetwork.Vec(MyNeuralNetwork.VarCov.times(-1)).getMatrix(0,dimv-2,0,0)),V,V).print(6,4);
//
//need to prove that sysmat = N is rank V-1 when directed network connected and where edge weight vector is pos and vertex weight vector is non-negative
//imagine a system where a connected directed network topology is chosen and programmed with edge weights and vertex weights
//to yield a specified covariance matrix at equilibrium for the neuron state random walk
//subject to correlated guassian white noise input AdW with a given covariance matrix A.AT
}
}
//***************************************************************************************************
//TwoBit.java as of 2015-01-24
package com.smkltd.app;
import java.util.BitSet; //to make a two bit two's complement array like object for totally unimodular matrix
import Jama.Matrix;
public class TwoBit
{
public int Rows;
public int Cols;
public int[][] LaplacianMatrix;
public double[][] LaplacianMatrixR;
public int[][] Adjacency;
public Matrix PKQTC;
private BitSet[][] twobit;
public TwoBit(int nrows, int ncols)
{
this.Rows = nrows;
this.Cols = ncols;
this.twobit = new BitSet[2][nrows];
for (int ii=0;ii<nrows;ii++)
{
this.twobit[0][ii] = new BitSet(ncols);
this.twobit[1][ii] = new BitSet(ncols);
}
}
public int Get(int r, int c)
{
int ii;
if (r>=Rows) {
throw new IllegalArgumentException("row index out of bounds in TwoBit.Get");
} else if (c>=Cols) {
throw new IllegalArgumentException("col index out of bounds in TwoBit.Get");
} else {
if ((twobit[0][r].get(c))&(twobit[1][r].get(c))) {
ii = -1;
} else if (!(twobit[0][r].get(c)) & !(twobit[1][r].get(c))) {
ii=0;
} else if (!(twobit[0][r].get(c)) & (twobit[1][r].get(c))) {
ii=1;
} else {
ii=-2;
}
}
return ii;
}
public void Set(int r, int c, int pm1v0)
{
if ((pm1v0!=-1)&(pm1v0!=0)&(pm1v0!=1)) {
throw new IllegalArgumentException("trying to set value <> -1,0,1 in TwoBit.Set");
} else if (r>=Rows) {
throw new IllegalArgumentException("row index out of bounds in TwoBit.Set");
} else if (c>=Cols) {
throw new IllegalArgumentException("col index out of bounds in TwoBit.Set");
} else {
if (pm1v0 == -1) {
twobit[0][r].set(c);
twobit[1][r].set(c);
} else if (pm1v0 == 0) {
twobit[0][r].clear(c);
twobit[1][r].clear(c);
} else if (pm1v0 == 1) {
twobit[0][r].clear(c);
twobit[1][r].set(c);
}
}
}
public int Pos(int r, int c)
{
int ii;
if (r>=Rows) {
throw new IllegalArgumentException("row index out of bounds in TwoBit.Get");
} else if (c>=Cols) {
throw new IllegalArgumentException("col index out of bounds in TwoBit.Get");
} else {
ii = Get(r,c);
if (ii<0) {
ii=0;
}
}
return ii;
}
public int Neg(int r, int c)
{
int ii;
if (r>=Rows) {
throw new IllegalArgumentException("row index out of bounds in TwoBit.Get");
} else if (c>=Cols) {
throw new IllegalArgumentException("col index out of bounds in TwoBit.Get");
} else {
ii = Get(r,c);
if (ii>0) {
ii=0;
}
}
return -ii;
}
public void Adjacency()
{
Adjacency = new int[Rows][Rows];
for (int ii=0; ii<Rows; ii++)
{
for (int jj=0; jj<Rows; jj++)
{
for (int kk=0; kk<Cols; kk++)
{
Adjacency[ii][jj] = Adjacency[ii][jj] + Pos(ii,kk)*Neg(jj,kk);
}
}
}
}
public void Adjacency(Matrix EdgeWeight, boolean normalized)
{
PKQTC = new Matrix(new double[Rows][Rows]);
for (int ii=0; ii<Rows; ii++)
{
for (int jj=0; jj<Rows; jj++)
{
for (int kk=0; kk<Cols; kk++)
{
PKQTC.set(ii,jj,PKQTC.get(ii,jj) + EdgeWeight.get(0,kk)*Pos(ii,kk)*Neg(jj,kk));
}
}
}
if (normalized) {
double w;
for (int ii=0; ii<Rows; ii++)
{
w=0;
for (int jj=0; jj<Rows; jj++)
{
w = w + PKQTC.get(ii,jj);
}
for (int jj=0; jj<Rows; jj++)
{
PKQTC.set(ii,jj,PKQTC.get(ii,jj)/w);
}
}
}
}
public void Adjacency(Matrix EdgeWeight, Matrix VertexWeight, boolean normalized)
{
Adjacency(EdgeWeight,false);
for (int ii=0; ii<Rows; ii++)
{
PKQTC.set(ii,ii,VertexWeight.get(ii,0));
}
if (normalized) {
double w;
for (int ii=0; ii<Rows; ii++)
{
w=0;
for (int jj=0; jj<Rows; jj++)
{
w = w + PKQTC.get(ii,jj);
}
for (int jj=0; jj<Rows; jj++)
{
PKQTC.set(ii,jj,PKQTC.get(ii,jj)/w);
}
}
}
}
public int Laplacian(int r, int c)
{
//also called the Kirchhoff matrix
int lp;
if (r>=Rows) {
throw new IllegalArgumentException("row index out of bounds in TwoBit.Laplacian");
} else if (c>=Rows) {
throw new IllegalArgumentException("col index out of bounds in TwoBit.Laplacian");
} else {
lp = 0;
for (int ii=0; ii<Cols; ii++)
{
lp = lp + Get(r,ii)*Get(c,ii);
}
}
return lp;
}
public int Laplacian(int r, int c, int[] K)
{
//also called the Kirchhoff matrix
int lp;
if (r>=Rows) {
throw new IllegalArgumentException("row index out of bounds in TwoBit.Laplacian");
} else if (c>=Rows) {
throw new IllegalArgumentException("col index out of bounds in TwoBit.Laplacian");
} else if (K.length!=Cols) {
throw new IllegalArgumentException("K[] has incorrect length in TwoBit.Laplacian");
} else {
lp = 0;
for (int ii=0; ii<Cols; ii++)
{
lp = lp + Get(r,ii)*Get(c,ii)*K[c];
}
}
return lp;
}
public double Laplacian(int r, int c, double[] K)
{
//also called the Kirchhoff matrix
double lp;
if (r>=Rows) {
throw new IllegalArgumentException("row index out of bounds in TwoBit.Laplacian");
} else if (c>=Rows) {
throw new IllegalArgumentException("col index out of bounds in TwoBit.Laplacian");
} else if (K.length!=Cols) {
throw new IllegalArgumentException("R[] has incorrect length in TwoBit.Laplacian");
} else {
lp = 0;
for (int ii=0; ii<Cols; ii++)
{
lp = lp + Get(r,ii)*Get(c,ii)*K[c];
}
}
return lp;
}
public void LaplacianMatrix()
{
LaplacianMatrix = new int[Rows][Rows];
for (int ii=0; ii<Rows; ii++)
{
for (int jj=0; jj<Rows; jj++)
{
LaplacianMatrix[ii][jj]=Laplacian(ii,jj);
}
}
}
public void LaplacianMatrixR(double[] CondR)
{
LaplacianMatrixR = new double[Rows][Rows];
for (int ii=0; ii<Rows; ii++)
{
for (int jj=0; jj<Rows; jj++)
{
LaplacianMatrixR[ii][jj]=Laplacian(ii,jj,CondR);
}
}
}
public void xchange(int pvtr, int pvtc)
{
if (pvtr>=Rows) {
throw new IllegalArgumentException("row index out of bounds in TwoBit.xchange()");
} else if (pvtc>=Cols) {
throw new IllegalArgumentException("col index out of bounds in TwoBit.xchange()");
} else if (Get(pvtr,pvtc)==0) {
throw new IllegalArgumentException("Illegal pivot element in TwoBit.xchange()");
} else {
for (int ii=0; ii<Rows; ii++) //need to catch a not totally unimodular condition though set() will bomb in this case
{
for (int jj=0; jj<Cols; jj++)
{
if ((ii!=pvtr) & (jj!=pvtc)) {
Set(ii,jj,(Get(ii,jj)-Get(ii,pvtc)*Get(pvtr,jj)/Get(pvtr,pvtc)));
}
}
if (ii!=pvtr) {
Set(ii,pvtc,(Get(ii,pvtc)/Get(pvtr,pvtc)));
}
}
for(int jj=0; jj<Cols; jj++)
{
if (jj!=pvtc) {
Set(pvtr,jj,(-Get(pvtr,jj)/Get(pvtr,pvtc)));
}
}
Set(pvtr,pvtc,(1/Get(pvtr,pvtc)));
}
}
public static void main( String[] args )
{
int v = 5;
int e;
e=(int)(v*(v-1)/2);
TwoBit mytwobit = new TwoBit(v,e);
//mytwobit.Create(v,e);
int kk=-1;
for (int ii=0; ii<v-1;ii++)
{
for (int jj=ii+1; jj<v;jj++)
{
kk=kk+1;
mytwobit.Set(ii,kk,1);
mytwobit.Set(jj,kk,-1);
}
}
System.out.println(" ");
for (int ii=0; ii<mytwobit.Rows;ii++)
{
for (int jj=0; jj<mytwobit.Cols;jj++)
{
System.out.printf("%2d ", mytwobit.Get(ii,jj));
}
System.out.println("");
}
}
}