Skip to content

Commit

Permalink
Merge pull request #250 from dmsl/develop
Browse files Browse the repository at this point in the history
Anyplace v3.4 Release (June 2018)
  • Loading branch information
dzeina authored Jun 8, 2018
2 parents 20fce6b + b3afc5f commit c6a66d0
Show file tree
Hide file tree
Showing 38 changed files with 1,487 additions and 374 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# AnyPlace v3.3 (April 2018)
# AnyPlace v3.4 (June 2018)

[![Join the chat at https://gitter.im/dmsl/anyplace](https://badges.gitter.im/dmsl/anyplace.svg)](https://gitter.im/dmsl/anyplace?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

Expand Down
14 changes: 9 additions & 5 deletions server/anyplace_tiler/anyplace-tiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,10 @@ def convertPaddedImage( filename, newW, newH, outputName ):


def resizeImage( srcImage, zoomOriginal, zoomCurrent, destImage ):
resRatio = 50#100.0 / (2 ** (zoomOriginal-zoomCurrent) )
rasRatio=100
if(zoomOriginal!=zoomCurrent):
resRatio = 100.0 / (2 ** (zoomOriginal-zoomCurrent) )
print(resRatio)
dim = subprocess.Popen(["convert", srcImage, "-resize", ('%d%%'%(resRatio)), destImage ], stdout=subprocess.PIPE).communicate()[0]

#####################################################################################
Expand Down Expand Up @@ -174,7 +177,7 @@ def fixTileStructure( fixTileStructureScript, ImageFileName ):
def main( argv ):
print( argv )

if(7 != len(sys.argv)):
if(8 != len(sys.argv)):
print(usage())
sys.exit(1)

Expand All @@ -184,6 +187,7 @@ def main( argv ):
OriginalZoom = int(sys.argv[4])
ToZoom = int(sys.argv[5])
ImageFileName = sys.argv[6]
UploadZoom = int(sys.argv[7])
ImageDirName = os.path.dirname(os.path.realpath(ImageFileName))

fixTileStructureScript = str(ScriptsDir + '/fix-tile-structure.sh')
Expand All @@ -195,13 +199,13 @@ def main( argv ):

# we will run the procedure for every zoom level in range [OriginalZoom..ToZoom]
for currentZoom in range( OriginalZoom, (ToZoom-1), -1 ):

currentImage=ImageFileName
# call the command to resize the image according to the zoom level
if( currentZoom == OriginalZoom ):
if( currentZoom == UploadZoom ):
currentImage=ImageFileName
else:
newName=(('%s-z%d.png') % (CURRENT_ZOOM_IMAGE_NAME, currentZoom))
resizeImage(currentImage, OriginalZoom, currentZoom, newName)
resizeImage(currentImage, UploadZoom, currentZoom, newName)
currentImage = newName

# get the Image top left world coords
Expand Down
7 changes: 4 additions & 3 deletions server/anyplace_tiler/start-anyplace-tiler.sh
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ check_requirements(){

##################### MAIN

[[ "$#" != "4" ]] && usage
[[ "$#" != "5" ]] && usage

[[ "$4" != "-ENLOG" && "$4" != "-DISLOG" ]] && usage

Expand Down Expand Up @@ -96,16 +96,17 @@ echo "Image: $imagePath"

ImageLatitude="$2"
ImageLongitude="$3"
ZoomOriginal=21
ZoomOriginal=22
ZoomDestination=19
ImageFileName="$imagePath"
UploadZoom="$5"


echo
echo ":: Starting anyplace-tiler ..."
anyTiler="$scriptsDir/anyplace-tiler.py"

python "$anyTiler" "$scriptsDir" "$ImageLatitude" "$ImageLongitude" "$ZoomOriginal" "$ZoomDestination" "$ImageFileName"
python "$anyTiler" "$scriptsDir" "$ImageLatitude" "$ImageLongitude" "$ZoomOriginal" "$ZoomDestination" "$ImageFileName" "$UploadZoom"
check_for_errors

echo
Expand Down
35 changes: 22 additions & 13 deletions server/app/acces/ACCES_RBF.scala
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,10 @@ class AccesRBF(
}
val _selected_features: IndexedSeq[Int] = select_features(Y=Y, Y_min=_Y_min, Y_max=_Y_max,
cut_k_features.getOrElse(Y.cols), drop_redundant = drop_redundant_features)
val _Y_normed = normalize_Y(
Y=(Y(::, _selected_features)).toDenseMatrix,
Y_means=(_Y_means(_selected_features)).toDenseVector)
// val _Y_normed = normalize_Y(
// Y=(Y(::, _selected_features)).toDenseMatrix,
// Y_means=(_Y_means(_selected_features)).toDenseVector)
val _Y_normed = normalize_Y( Y=Y, Y_means=_Y_means)

println("x_min", _X_min)
println("x_max", _X_max)
Expand Down Expand Up @@ -113,7 +114,8 @@ class AccesRBF(


def select_features(Y: DenseMatrix[Double], Y_min: DenseVector[Double], Y_max: DenseVector[Double],
k_features: Int, drop_redundant: Boolean = true): IndexedSeq[Int] = {
k_features: Int, drop_redundant: Boolean = true,
rtol: Double = 0.01, atol: Double = 0.00001): IndexedSeq[Int] = {
if (k_features <= 0) { throw new IllegalArgumentException("k_features must be positive")}
val k = if (k_features > Y.cols) Y.cols else k_features

Expand All @@ -122,7 +124,7 @@ class AccesRBF(
println("select_features: Y_max", Y_max)
val scores = DenseVector.zeros[Double](k)
for (i <- 0 to k - 1) {
scores(i) = meanAndVariance(Y(::, i)).variance / (Y_max(i) - Y_min(i))
scores(i) = sqrt(meanAndVariance(Y(::, i)).variance) / (Y_max(i) - Y_min(i))
}
var inds = argsort(scores).reverse
println("scores", scores)
Expand All @@ -134,35 +136,41 @@ class AccesRBF(
for (i <- 0 to inds.length - 1) {
val ind = inds(i)
println("ind", ind, "var", scores(i))
if (~=(scores(ind), 0.0, 0.00001)) {
if (~=(scores(ind), 0, atol) || scores(ind) / scores(inds(0)) < rtol) {
inds = inds.slice(0, i)
println(inds)
break
}
// if (~=(scores(ind), 0.0, 0.00001)) {
// inds = inds.slice(0, i)
// println(inds)
// break
// }
}
}
}
inds = inds.slice(0, min(inds.length, k))
inds = inds.sorted

println("new inds", inds)
println("new scores", scores(inds).toDenseVector)
// println("new inds", inds)
// println("new scores", scores(inds).toDenseVector)

return inds
}

def fit_gpr(estimate: Boolean = false, use_default_params: Boolean = false) = {
val X: DenseMatrix[Double] = this._X_normed
val Y: DenseMatrix[Double] = this._Y_normed(::, this._selected_features).toDenseMatrix
val X_min = this._X_min
val X_max = this._X_max
val X_min = min(X(::, *)).t
val X_max = max(X(::, *)).t
val Y_min = this._Y_min(this._selected_features).toDenseVector
val Y_max = this._Y_max(this._selected_features).toDenseVector

val n = X.rows
val d = X.cols
val m = Y.cols

println("X.rows, Y.rows: ", X.rows, Y.rows)
assert(X.rows == Y.rows)

if(estimate) {
Expand All @@ -176,7 +184,7 @@ class AccesRBF(
println("use default parameters", use_default_params)

val sf_0: DenseVector[Double] = 0.01 * (Y_max - Y_min)
val l_0: DenseVector[Double] = 0.1 * DenseVector.ones[Double](m)
val l_0: DenseVector[Double] = 0.1 * breeze.linalg.norm(X_max - X_min) * DenseVector.ones[Double](m)
val noise_0: DenseVector[Double] = sf_0.copy

println("Default parameters")
Expand Down Expand Up @@ -264,6 +272,7 @@ class AccesRBF(
}

def predict_gpr_scalar(X: DenseMatrix[Double], component: Int): (DenseVector[Double],DenseVector[Double]) = {
// WRONG INDEXING HERE, component for M and data is not the same, need to fix
if (!this._selected_features.contains(component)) {
throw new IllegalArgumentException("Feature %d is ignored".format(component))
}
Expand Down Expand Up @@ -411,7 +420,7 @@ class AccesRBF(
// println("x", x)
// println("x_normed", x_normed)
val X_normed = this._X_normed
val Y_normed = this._Y_normed
val Y_normed = this._Y_normed(::, this._selected_features).toDenseMatrix
val m = Y_normed.cols
val n = X_normed.rows
val d = X_normed.cols
Expand All @@ -420,7 +429,7 @@ class AccesRBF(
// var FIM = DenseMatrix.zeros[Double](d,d)
val FIMs: Array[DenseMatrix[Double]] = Array.ofDim[DenseMatrix[Double]](this._selected_features.length)

for (i <- 0 to this._selected_features.length - 1) {
for (i <- 0 until Y_normed.cols) {
var FIM = DenseMatrix.zeros[Double](d,d)
val M = this._Ms.get(i)
val gamma = this._gammas.get(i)
Expand Down
Loading

0 comments on commit c6a66d0

Please sign in to comment.