require 'routing.rb' ns=Nodes.new(100,2) ns.computeDistances baseNode=ns.nodes[0] gr=GlobalRouting.new(baseNode,ns) neighbor=baseNode.neighbors[0] lr=LocalRouting.new(neighbor,ns) newNeighbors=(lr.neighbors-baseNode.neighbors) puts "__" puts newNeighbors newNeighbor=newNeighbors[0] pos=lr.getNodePos(newNeighbor) tpos=gr.translateFromNeighborToLocal(pos,neighbor) #pp pos pp tpos exit localRouting=LocalRouting.new(baseNode,ns) neighbor=baseNode.neighbors[0] p=localRouting.getNodePos(neighbor) pp p rVec=localRouting.routeVector(p) pp rVec pp localRouting.routeVectorDirect(neighbor) exit neighborNodes=baseNode.neighborHood(2) puts "NEIGHBORS",neighborNodes.length assert{!neighborNodes.member?(baseNode)} m=ns.createMatrix(neighborNodes) mInv=Linalg::DMatrix[*m].pseudo_inverse base=PCA::Base.new(PCA::Input.new(m)) base.reduce([base.dimension-2,8].min) pp base.dimension pp base.measureSingleError(ns.createDistances(neighborNodes,ns.nodes[50])) routingMatrix=ns.computeRoutingMatrix(baseNode,neighborNodes) neighborNodes.each{|n| dVec=m[neighborNodes.index(n)] pp dVec pos=base.compress(dVec) vpos=base.decompress(pos) pp "---" pp dVec,vpos tmpRes=(mInv*(vpos.transpose)) res=routingMatrix*(mInv*(vpos.transpose)) pp "RES:",res check=Linalg::DMatrix[[1]+[0]*(tmpRes.vsize-1)] pp check pp routingMatrix*check.transpose exit } #pp base exit 30.downto(1){|i| base.reduce(i) pp i pp base.measureErrors(m) }