Search in sources :

Example 1 with TIntArrayList

use of gnu.trove.list.array.TIntArrayList in project JGibbLabeledLDA by myleott.

the class LDADataset method addDoc.

/**
     * add a new document
     * @param str string contains doc
     */
public void addDoc(String str, boolean unlabeled) {
    // read document labels (if provided)
    TIntArrayList labels = null;
    if (str.startsWith("[")) {
        String[] labelsBoundary = str.substring(// remove initial '['
        1).split("]", // separate labels and str between ']'
        2);
        String[] labelStrs = labelsBoundary[0].trim().split("[ \\t]");
        str = labelsBoundary[1].trim();
        // parse labels (unless we're ignoring the labels)
        if (!unlabeled) {
            // store labels in a HashSet to ensure uniqueness
            TIntHashSet label_set = new TIntHashSet();
            for (String labelStr : labelStrs) {
                try {
                    label_set.add(Integer.parseInt(labelStr.trim()));
                } catch (NumberFormatException nfe) {
                    System.err.println("Unknown document label ( " + labelStr + " ) for document " + docs.size() + ".");
                }
            }
            labels = new TIntArrayList(label_set);
            labels.sort();
        }
    }
    String[] words = str.split("[ \\t\\n]");
    TIntArrayList ids = new TIntArrayList();
    for (String word : words) {
        if (word.trim().equals("")) {
            continue;
        }
        int _id = localDict.word2id.size();
        if (localDict.contains(word))
            _id = localDict.getID(word);
        if (globalDict != null) {
            //get the global id					
            if (globalDict.contains(word)) {
                localDict.addWord(word);
                lid2gid.put(_id, globalDict.getID(word));
                ids.add(_id);
            }
        } else {
            localDict.addWord(word);
            ids.add(_id);
        }
    }
    setDoc(new Document(ids, str, labels), docs.size());
    V = localDict.word2id.size();
}
Also used : TIntArrayList(gnu.trove.list.array.TIntArrayList) TIntHashSet(gnu.trove.set.hash.TIntHashSet)

Example 2 with TIntArrayList

use of gnu.trove.list.array.TIntArrayList in project JGibbLabeledLDA by myleott.

the class Model method readTAssignFile.

/**
     * Load word-topic assignments for this model
     */
protected boolean readTAssignFile(String tassignFile) {
    try {
        int i, j;
        BufferedReader reader = new BufferedReader(new InputStreamReader(new GZIPInputStream(new FileInputStream(tassignFile)), "UTF-8"));
        String line;
        z = new TIntArrayList[M];
        data = new LDADataset();
        data.setM(M);
        data.V = V;
        for (i = 0; i < M; i++) {
            line = reader.readLine();
            StringTokenizer tknr = new StringTokenizer(line, " \t\r\n");
            int length = tknr.countTokens();
            TIntArrayList words = new TIntArrayList();
            TIntArrayList topics = new TIntArrayList();
            for (j = 0; j < length; j++) {
                String token = tknr.nextToken();
                StringTokenizer tknr2 = new StringTokenizer(token, ":");
                if (tknr2.countTokens() != 2) {
                    System.out.println("Invalid word-topic assignment line\n");
                    return false;
                }
                words.add(Integer.parseInt(tknr2.nextToken()));
                topics.add(Integer.parseInt(tknr2.nextToken()));
            }
            //end for each topic assignment
            //allocate and add new document to the corpus
            Document doc = new Document(words);
            data.setDoc(doc, i);
            //assign values for z
            z[i] = new TIntArrayList();
            for (j = 0; j < topics.size(); j++) {
                z[i].add(topics.get(j));
            }
        }
        //end for each doc
        reader.close();
    } catch (Exception e) {
        System.out.println("Error while loading model: " + e.getMessage());
        e.printStackTrace();
        return false;
    }
    return true;
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) StringTokenizer(java.util.StringTokenizer) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) FileInputStream(java.io.FileInputStream) TIntArrayList(gnu.trove.list.array.TIntArrayList) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 3 with TIntArrayList

use of gnu.trove.list.array.TIntArrayList in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class WorldPhysicsCollider method updatePotentialCollisionCache.

private void updatePotentialCollisionCache() {
    final AxisAlignedBB collisionBB = parent.collisionBB.expand(expansion, expansion, expansion).addCoord(calculator.linearMomentum.X * calculator.invMass, calculator.linearMomentum.Y * calculator.invMass, calculator.linearMomentum.Z * calculator.invMass);
    ticksSinceCacheUpdate = 0D;
    //in the same tick
    if (Math.random() > .5) {
        ticksSinceCacheUpdate -= .05D;
    }
    // cachedPotentialHits = new ArrayList<BlockPos>();
    cachedPotentialHits = new TIntArrayList();
    // Ship is outside of world blockSpace, just skip this all together
    if (collisionBB.maxY < 0 || collisionBB.minY > 255) {
        // internalCachedPotentialHits = new BlockPos[0];
        return;
    }
    //Has a -1 on the minY value, I hope this helps with preventing things from falling through the floor
    final BlockPos min = new BlockPos(collisionBB.minX, Math.max(collisionBB.minY - 1, 0), collisionBB.minZ);
    final BlockPos max = new BlockPos(collisionBB.maxX, Math.min(collisionBB.maxY, 255), collisionBB.maxZ);
    centerPotentialHit = new BlockPos((min.getX() + max.getX()) / 2D, (min.getY() + max.getY()) / 2D, (min.getZ() + max.getZ()) / 2D);
    final ChunkCache cache = parent.surroundingWorldChunksCache;
    final Vector inLocal = new Vector();
    int maxX, maxY, maxZ, localX, localY, localZ, x, y, z, chunkX, chunkZ;
    double rangeCheck = 1.8D;
    if (ValkyrienWarfareMod.highAccuracyCollisions) {
        rangeCheck = 3D;
    }
    Chunk chunk, chunkIn;
    ExtendedBlockStorage extendedblockstorage;
    IBlockState state, localState;
    int chunkMinX = min.getX() >> 4;
    int chunkMaxX = (max.getX() >> 4) + 1;
    int storageMinY = min.getY() >> 4;
    int storageMaxY = (max.getY() >> 4) + 1;
    int chunkMinZ = min.getZ() >> 4;
    int chunkMaxZ = (max.getZ() >> 4) + 1;
    int storageY;
    int mmX = min.getX(), mmY = min.getY(), mmZ = min.getZ(), mxX = max.getX(), mxY = max.getY(), mxZ = max.getZ();
    Vector inBody = new Vector();
    Vector speedInBody = new Vector();
    for (chunkX = chunkMinX; chunkX < chunkMaxX; chunkX++) {
        for (chunkZ = chunkMinZ; chunkZ < chunkMaxZ; chunkZ++) {
            int arrayChunkX = chunkX - cache.chunkX;
            int arrayChunkZ = chunkZ - cache.chunkZ;
            if (!(arrayChunkX < 0 || arrayChunkZ < 0 || arrayChunkX > cache.chunkArray.length - 1 || arrayChunkZ > cache.chunkArray[0].length - 1)) {
                chunk = cache.chunkArray[arrayChunkX][arrayChunkZ];
                for (storageY = storageMinY; storageY < storageMaxY; storageY++) {
                    extendedblockstorage = chunk.storageArrays[storageY];
                    if (extendedblockstorage != null) {
                        int minStorageX = chunkX << 4;
                        int minStorageY = storageY << 4;
                        int minStorageZ = chunkZ << 4;
                        int maxStorageX = minStorageX + 16;
                        int maxStorageY = minStorageY + 16;
                        int maxStorageZ = minStorageZ + 16;
                        minStorageX = Math.max(minStorageX, mmX);
                        minStorageY = Math.max(minStorageY, mmY);
                        minStorageZ = Math.max(minStorageZ, mmZ);
                        maxStorageX = Math.min(maxStorageX, mxX);
                        maxStorageY = Math.min(maxStorageY, mxY);
                        maxStorageZ = Math.min(maxStorageZ, mxZ);
                        for (x = minStorageX; x < maxStorageX; x++) {
                            for (y = minStorageY; y < maxStorageY; y++) {
                                for (z = minStorageZ; z < maxStorageZ; z++) {
                                    state = extendedblockstorage.get(x & 15, y & 15, z & 15);
                                    if (state.getMaterial().isSolid()) {
                                        inLocal.X = x + .5D;
                                        inLocal.Y = y + .5D;
                                        inLocal.Z = z + .5D;
                                        parent.coordTransform.fromGlobalToLocal(inLocal);
                                        inBody.setSubtraction(inLocal, parent.centerCoord);
                                        parent.physicsProcessor.setVectorToVelocityAtPoint(inBody, speedInBody);
                                        speedInBody.multiply(-parent.physicsProcessor.physRawSpeed);
                                        if (ValkyrienWarfareMod.highAccuracyCollisions) {
                                            speedInBody.multiply(20D);
                                        }
                                        //											System.out.println(speedInBody);
                                        int minX, minY, minZ;
                                        if (speedInBody.X > 0) {
                                            minX = MathHelper.floor_double(inLocal.X - rangeCheck);
                                            maxX = MathHelper.floor_double(inLocal.X + rangeCheck + speedInBody.X);
                                        } else {
                                            minX = MathHelper.floor_double(inLocal.X - rangeCheck + speedInBody.X);
                                            maxX = MathHelper.floor_double(inLocal.X + rangeCheck);
                                        }
                                        if (speedInBody.Y > 0) {
                                            minY = MathHelper.floor_double(inLocal.Y - rangeCheck);
                                            maxY = MathHelper.floor_double(inLocal.Y + rangeCheck + speedInBody.Y);
                                        } else {
                                            minY = MathHelper.floor_double(inLocal.Y - rangeCheck + speedInBody.Y);
                                            maxY = MathHelper.floor_double(inLocal.Y + rangeCheck);
                                        }
                                        if (speedInBody.Z > 0) {
                                            minZ = MathHelper.floor_double(inLocal.Z - rangeCheck);
                                            maxZ = MathHelper.floor_double(inLocal.Z + rangeCheck + speedInBody.Z);
                                        } else {
                                            minZ = MathHelper.floor_double(inLocal.Z - rangeCheck + speedInBody.Z);
                                            maxZ = MathHelper.floor_double(inLocal.Z + rangeCheck);
                                        }
                                        /** The Old Way of doing things; approx. 33% slower overall when running this code instead of new
											for (localX = minX; localX < maxX; localX++) {
												for (localZ = minZ; localZ < maxZ; localZ++) {
													for (localY = minY; localY < maxY; localY++) {
														if (parent.ownsChunk(localX >> 4, localZ >> 4)) {
															chunkIn = parent.VKChunkCache.getChunkAt(localX >> 4, localZ >> 4);
															localState = chunkIn.getBlockState(localX, localY, localZ);
															if (localState.getMaterial().isSolid()) {
																cachedPotentialHits.add(SpatialDetector.getHashWithRespectTo(x, y, z, centerPotentialHit));
																localX = localY = localZ = Integer.MAX_VALUE - 420;
															}
														}
													}
												}
											}
											**/
                                        int shipChunkMinX = minX >> 4;
                                        int shipChunkMinY = Math.max(minY >> 4, 0);
                                        int shipChunkMinZ = minZ >> 4;
                                        int shipChunkMaxX = maxX >> 4;
                                        int shipChunkMaxY = Math.min(maxY >> 4, 15);
                                        int shipChunkMaxZ = maxZ >> 4;
                                        shipChunkMaxX++;
                                        shipChunkMaxY++;
                                        shipChunkMaxZ++;
                                        if (shipChunkMaxZ - shipChunkMinZ > 200 || shipChunkMaxX - shipChunkMinX > 200) {
                                            System.err.println("Wtf. This fucking error");
                                            return;
                                        }
                                        testForNearbyBlocks: for (int shipChunkX = shipChunkMinX; shipChunkX < shipChunkMaxX; shipChunkX++) {
                                            for (int shipChunkZ = shipChunkMinZ; shipChunkZ < shipChunkMaxZ; shipChunkZ++) {
                                                if (parent.ownsChunk(shipChunkX, shipChunkZ)) {
                                                    chunkIn = parent.VKChunkCache.getChunkAt(shipChunkX, shipChunkZ);
                                                    for (int shipChunkYStorage = shipChunkMinY; shipChunkYStorage < shipChunkMaxY; shipChunkYStorage++) {
                                                        ExtendedBlockStorage storage = chunkIn.storageArrays[shipChunkYStorage];
                                                        if (storage != null) {
                                                            int shipStorageMinX = shipChunkX << 4;
                                                            int shipStorageMinY = shipChunkYStorage << 4;
                                                            int shipStorageMinZ = shipChunkZ << 4;
                                                            int shipStorageMaxX = shipStorageMinX + 16;
                                                            int shipStorageMaxY = shipStorageMinY + 16;
                                                            int shipStorageMaxZ = shipStorageMinZ + 16;
                                                            shipStorageMinX = Math.max(shipStorageMinX, minX);
                                                            shipStorageMinY = Math.max(shipStorageMinY, minY);
                                                            shipStorageMinZ = Math.max(shipStorageMinZ, minZ);
                                                            shipStorageMaxX = Math.min(shipStorageMaxX, maxX);
                                                            shipStorageMaxY = Math.min(shipStorageMaxY, maxY);
                                                            shipStorageMaxZ = Math.min(shipStorageMaxZ, maxZ);
                                                            for (localX = shipStorageMinX; localX < shipStorageMaxX; localX++) {
                                                                for (localY = shipStorageMinY; localY < shipStorageMaxY; localY++) {
                                                                    for (localZ = shipStorageMinZ; localZ < shipStorageMaxZ; localZ++) {
                                                                        localState = chunkIn.getBlockState(localX, localY, localZ);
                                                                        if (localState.getMaterial().isSolid()) {
                                                                            cachedPotentialHits.add(SpatialDetector.getHashWithRespectTo(x, y, z, centerPotentialHit));
                                                                            break testForNearbyBlocks;
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    /**
		for (x = min.getX(); x <= max.getX(); x++) {
			for (z = min.getZ(); z < max.getZ(); z++) {
				chunkX = (x >> 4) - cache.chunkX;
				chunkZ = (z >> 4) - cache.chunkZ;
				if (!(chunkX < 0 || chunkZ < 0 || chunkX > cache.chunkArray.length - 1 || chunkZ > cache.chunkArray[0].length - 1)) {
					chunk = cache.chunkArray[chunkX][chunkZ];
					for (y = min.getY(); y < max.getY(); y++) {
						extendedblockstorage = chunk.storageArrays[y >> 4];
						if (extendedblockstorage != null) {
							state = extendedblockstorage.get(x & 15, y & 15, z & 15);

							if (state.getMaterial().isSolid()) {
								inLocal.X = x + .5D;
								inLocal.Y = y + .5D;
								inLocal.Z = z + .5D;
								parent.coordTransform.fromGlobalToLocal(inLocal);

								maxX = (int) Math.floor(inLocal.X + rangeCheck);
								maxY = (int) Math.floor(inLocal.Y + rangeCheck);
								maxZ = (int) Math.floor(inLocal.Z + rangeCheck);

								for (localX = MathHelper.floor_double(inLocal.X - rangeCheck); localX < maxX; localX++) {
									for (localZ = MathHelper.floor_double(inLocal.Z - rangeCheck); localZ < maxZ; localZ++) {
										for (localY = MathHelper.floor_double(inLocal.Y - rangeCheck); localY < maxY; localY++) {
											if (parent.ownsChunk(localX >> 4, localZ >> 4)) {
												chunkIn = parent.VKChunkCache.getChunkAt(localX >> 4, localZ >> 4);
												localState = chunkIn.getBlockState(localX, localY, localZ);
												if (localState.getMaterial().isSolid()) {
													cachedPotentialHits.add(SpatialDetector.getHashWithRespectTo(x, y, z, centerPotentialHit));
													localX = localY = localZ = Integer.MAX_VALUE - 420;
												}
											}
										}
									}
								}
							}
						}
					}
				}
			}
		}
		**/
    cachedPotentialHits.shuffle(rand);
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) IBlockState(net.minecraft.block.state.IBlockState) ChunkCache(net.minecraft.world.ChunkCache) BlockPos(net.minecraft.util.math.BlockPos) MutableBlockPos(net.minecraft.util.math.BlockPos.MutableBlockPos) Chunk(net.minecraft.world.chunk.Chunk) ExtendedBlockStorage(net.minecraft.world.chunk.storage.ExtendedBlockStorage) Vector(ValkyrienWarfareBase.API.Vector) TIntArrayList(gnu.trove.list.array.TIntArrayList)

Example 4 with TIntArrayList

use of gnu.trove.list.array.TIntArrayList in project ProPPR by TeamCohen.

the class LightweightStateGraph method serialize.

public String serialize(boolean featureIndex) {
    StringBuilder ret = //numNodes
    new StringBuilder().append(this.nodeSize()).append("\t").append(this.edgeCount).append(// waiting for label dependency size
    "\t");
    int labelDependencies = 0;
    StringBuilder sb = new StringBuilder();
    boolean first = true;
    if (featureIndex) {
        sb.append("\t");
        for (int fi = 1; fi <= this.featureTab.size(); fi++) {
            if (!first)
                sb.append(LearningGraphBuilder.FEATURE_INDEX_DELIM);
            else
                first = false;
            Feature f = this.featureTab.getSymbol(fi);
            sb.append(f);
        }
    }
    // foreach src node
    for (TIntObjectIterator<TIntArrayList> it = this.near.iterator(); it.hasNext(); ) {
        it.advance();
        int ui = it.key();
        TIntArrayList nearu = it.value();
        HashSet<Integer> outgoingFeatures = new HashSet<Integer>();
        //foreach dst from src
        for (TIntIterator vit = nearu.iterator(); vit.hasNext(); ) {
            int vi = vit.next();
            sb.append("\t");
            sb.append(ui).append(LearningGraphBuilder.SRC_DST_DELIM).append(vi);
            sb.append(LearningGraphBuilder.EDGE_DELIM);
            //foreach feature on src,dst
            for (TIntDoubleIterator fit = edgeFeatureDict.get(ui).get(vi).iterator(); fit.hasNext(); ) {
                fit.advance();
                int fi = fit.key();
                double wi = fit.value();
                outgoingFeatures.add(fi);
                sb.append(fi).append(LearningGraphBuilder.FEATURE_WEIGHT_DELIM).append(wi).append(LearningGraphBuilder.EDGE_FEATURE_DELIM);
            }
            // drop last ','
            sb.deleteCharAt(sb.length() - 1);
        }
        labelDependencies += outgoingFeatures.size() * nearu.size();
    }
    ret.append(labelDependencies).append(sb);
    return ret.toString();
}
Also used : TIntIterator(gnu.trove.iterator.TIntIterator) TIntDoubleIterator(gnu.trove.iterator.TIntDoubleIterator) Feature(edu.cmu.ml.proppr.prove.wam.Feature) TIntArrayList(gnu.trove.list.array.TIntArrayList) HashSet(java.util.HashSet)

Example 5 with TIntArrayList

use of gnu.trove.list.array.TIntArrayList in project ProPPR by TeamCohen.

the class LightweightStateGraph method setOutlinks.

public void setOutlinks(State u, List<Outlink> outlinks) {
    // wwc: why are we saving these outlinks as a trove thing? space?
    int ui = this.nodeTab.getId(u);
    if (near.containsKey(ui)) {
        log.warn("Overwriting previous outlinks for state " + u);
        edgeCount -= near.get(ui).size();
    }
    TIntArrayList nearui = new TIntArrayList(outlinks.size());
    near.put(ui, nearui);
    TIntObjectHashMap<TIntDoubleHashMap> fui = new TIntObjectHashMap<TIntDoubleHashMap>();
    edgeFeatureDict.put(ui, fui);
    for (Outlink o : outlinks) {
        int vi = this.nodeTab.getId(o.child);
        nearui.add(vi);
        edgeCount++;
        TIntDoubleHashMap fvui = new TIntDoubleHashMap(o.fd.size());
        for (Map.Entry<Feature, Double> e : o.fd.entrySet()) {
            fvui.put(this.featureTab.getId(e.getKey()), e.getValue());
        }
        fui.put(vi, fvui);
    }
}
Also used : Outlink(edu.cmu.ml.proppr.prove.wam.Outlink) TIntDoubleHashMap(gnu.trove.map.hash.TIntDoubleHashMap) TIntObjectHashMap(gnu.trove.map.hash.TIntObjectHashMap) TIntObjectHashMap(gnu.trove.map.hash.TIntObjectHashMap) HashMap(java.util.HashMap) TIntDoubleHashMap(gnu.trove.map.hash.TIntDoubleHashMap) Map(java.util.Map) Feature(edu.cmu.ml.proppr.prove.wam.Feature) TIntArrayList(gnu.trove.list.array.TIntArrayList)

Aggregations

TIntArrayList (gnu.trove.list.array.TIntArrayList)10 Feature (edu.cmu.ml.proppr.prove.wam.Feature)2 TIntList (gnu.trove.list.TIntList)2 BlockPos (net.minecraft.util.math.BlockPos)2 Vector (ValkyrienWarfareBase.API.Vector)1 Outlink (edu.cmu.ml.proppr.prove.wam.Outlink)1 State (edu.cmu.ml.proppr.prove.wam.State)1 TIntDoubleIterator (gnu.trove.iterator.TIntDoubleIterator)1 TIntIterator (gnu.trove.iterator.TIntIterator)1 TIntDoubleHashMap (gnu.trove.map.hash.TIntDoubleHashMap)1 TIntObjectHashMap (gnu.trove.map.hash.TIntObjectHashMap)1 TIntProcedure (gnu.trove.procedure.TIntProcedure)1 TIntHashSet (gnu.trove.set.hash.TIntHashSet)1 IvMutableBlockPos (ivorius.ivtoolkit.blocks.IvMutableBlockPos)1 BufferedReader (java.io.BufferedReader)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 ArrayList (java.util.ArrayList)1