public static SparseTensor operator -(SparseTensor st1, SparseTensor st2) { SparseTensor newST = new SparseTensor(); foreach (KeyValuePair <int, SparseMatrix> kvp in st1.tensor) { if (st2.tensor.ContainsKey(kvp.Key)) { newST.tensor.Add(kvp.Key, kvp.Value - st2.getMatrix(kvp.Key)); } else { newST.tensor.Add(kvp.Key, kvp.Value); } } foreach (KeyValuePair <int, SparseMatrix> kvp in st2.tensor) { if (!st1.tensor.ContainsKey(kvp.Key)) { SparseMatrix tempMat = new SparseMatrix(); tempMat = tempMat - kvp.Value; newST.tensor.Add(kvp.Key, tempMat); } } return(newST); }
public void copy(SparseTensor ts) { foreach (int id in ts.tensor.Keys) { SparseMatrix mat = new SparseMatrix(); mat.copy(ts.tensor[id]); this.tensor.Add(id, mat); } }
public SparseTensor network; //objID->sparseMatrix(objID, type, attributeID, count) public Network(int n) { entityList = new Entity[n]; for (int i = 0; i < n; i++) { entityList[i] = new Entity(); } network = new SparseTensor(); }
public static Network operator +(Network net1, Network net2) { int n = net1.entityList.Length; Network curNet = new Network(n); Entity[] curEntList = new Entity[n]; //aggregate the entitylist for (int i = 0; i < n; i++) { curEntList[i] = new Entity(); curEntList[i].copy(net1.entityList[i]); curEntList[i].additems(net2.entityList[i]); } //aggregate the network SparseTensor curNetTensor = new SparseTensor(); curNetTensor = net1.network + net2.network; curNet.entityList = curEntList; curNet.network = curNetTensor; return curNet; }
public static SparseTensor operator -(SparseTensor st1, SparseTensor st2) { SparseTensor newST = new SparseTensor(); foreach (KeyValuePair<int, SparseMatrix> kvp in st1.tensor) { if (st2.tensor.ContainsKey(kvp.Key)) { newST.tensor.Add(kvp.Key, kvp.Value - st2.getMatrix(kvp.Key)); } else { newST.tensor.Add(kvp.Key, kvp.Value); } } foreach (KeyValuePair<int, SparseMatrix> kvp in st2.tensor) { if (!st1.tensor.ContainsKey(kvp.Key)) { SparseMatrix tempMat = new SparseMatrix(); tempMat = tempMat - kvp.Value; newST.tensor.Add(kvp.Key, tempMat); } } return newST; }