Skip to content

Instantly share code, notes, and snippets.

Avatar

Ruben Wolff reisepass

View GitHub Profile
View MaximizeByBPLoopy_rw.scala
package ch.ethz.dalab.dissolve.examples.neighbourhood
import cc.factorie.la._
import scala.collection.mutable.ArrayBuffer
import scala.collection.Set
import cc.factorie.util.{DoubleSeq, RangeIntSeq, SparseDoubleSeq}
import scala.collection.mutable
@reisepass
reisepass / MaximizeByBPLoopy_rw
Created Aug 19, 2015
Use this to change the number of iterations LoopyBP does
View MaximizeByBPLoopy_rw
package ch.ethz.dalab.dissolve.examples.neighbourhood
import cc.factorie.la._
import scala.collection.mutable.ArrayBuffer
import scala.collection.Set
import cc.factorie.util.{DoubleSeq, RangeIntSeq, SparseDoubleSeq}
import scala.collection.mutable
@reisepass
reisepass / gist:38c2b29f0b1bb53e27a9
Created Jul 28, 2015
error happens on aws but not locally
View gist:38c2b29f0b1bb53e27a9
/*
Exception in thread "main" java.lang.ClassCastException: breeze.linalg.Transpose cannot be cast to breeze.linalg.ImmutableNumericOps
at ch.ethz.dalab.dissolve.optimization.SolverUtils$.objectiveFunction(SolverUtils.scala:52)
at ch.ethz.dalab.dissolve.optimization.DBCFWSolverTuned.ch$ethz$dalab$dissolve$optimization$DBCFWSolverTuned$$evaluateModel$1(DBCFWSolverTuned.scala:237)
at ch.ethz.dalab.dissolve.optimization.DBCFWSolverTuned$$anonfun$optimize$1.apply$mcZI$sp(DBCFWSolverTuned.scala:375)
at ch.ethz.dalab.dissolve.optimization.DBCFWSolverTuned$$anonfun$optimize$1.apply(DBCFWSolverTuned.scala:359)
at ch.ethz.dalab.dissolve.optimization.DBCFWSolverTuned$$anonfun$optimize$1.apply(DBCFWSolverTuned.scala:359)
at scala.collection.immutable.Stream.takeWhile(Stream.scala:803)
at ch.ethz.dalab.dissolve.optimization.DBCFWSolverTuned.optimize(DBCFWSolverTuned.scala:358)
at ch.ethz.dalab.dissolve.classification.StructSVMWithDBCFW.trainModel(StructSVMWithDBCFW.scala:24)
@reisepass
reisepass / gist:e1b3b48bbbe8217fbfe6
Created Jun 30, 2015
Core portion of the Mean Field algorithm. Prettymuch one to one of the Matlab code
View gist:e1b3b48bbbe8217fbfe6
val Q = DenseMatrix.ones[Double](numRegions, numClasses)
var lastMaxE = 0.0
var lastMinE = 0.0
var numNoChange = 0
for (iter <- 0 until maxIterations) {
var numUnchangedQs = 0
val lastQ = Q;
val xiLab = (0 until numClasses).par
View gist:66e1cb60114bb62c0fac
val Q = DenseMatrix.ones[Double](numRegions, numClasses) //TODO maybe initialize to 1/num neighbours or 1/numneighbours*numClass
//TODO This Q could be stored in a spark RDD if it gets too large for memory;; Prob not necesary because thetaUnayr is the same size
//TODO consider storing the probabilities in a byte
if (debug) {
//val header = (0 until numClasses).toSeq.toList.flatMap { curclass => (0 until numRegions).toSeq.toList.map { curregion => ",Qr" + curregion + " Qc" + curclass } }
// println("#MF_Q_LOG#,timeID,elapsedTime" + header)
// println("#MF_E_LOG#,timeID,logTag,iter,maxE,minE,maxE_change,minE_change")
}
var lastMaxE = 0.0
View gist:83741e0bfce3d1c62b0c
class RegionVar(val score: Int) extends IntegerVariable(score)
object PixelDomain extends DiscreteDomain(numClasses)
class Pixel(i: Int) extends DiscreteVariable(i) { //i is just the initial value
def domain = PixelDomain
}
val labelParams = Array.fill(graph.size) { new Pixel(0) }
val nodePairsUsed: HashSet[(Int, Int)] = new HashSet[(Int, Int)]()
View gist:5689046
{
"d":{
"__type":"Response:http:\/\/research.microsoft.com",
"Author":null,
"Conference":null,
"Domain":null,
"Journal":null,
"Keyword":null,
"Organization":null,
"Publication":{
@reisepass
reisepass / gist:5631031
Last active Dec 17, 2015
Here is an example use case for the wildcard.
View gist:5631031
protected ArrayList<String> wildWithInpAtBack(String inp,int ngramLength){
ArrayList<String> out = new ArrayList<String>(ngramLength);
for(int i=0;i<ngramLength-1;i++){
out.add(i, FirstSentSum.WILDCARD_STRING);
}
if(inp.indexOf(" ")!=-1){
for(String sepI : inp.split(" ")){
out.add(sepI);
}
}