Skip to content

Instantly share code, notes, and snippets.

@putraxor
Created September 24, 2017 19:44
Show Gist options
  • Save putraxor/094e9326be715fdd64243eae88420d9a to your computer and use it in GitHub Desktop.
Save putraxor/094e9326be715fdd64243eae88420d9a to your computer and use it in GitHub Desktop.
Feature Extraction using Zone Based
package com.github.putraxor
/**
* Feature Extraction using Zone Based
*/
object ZonaFE {
/**
* Extract feature from matrix
* [z] number of zones
* [matrix] matrix to be extracted
* @return double array of zoned density
*/
fun extract(z: Int, matrix: List<List<Int>>): DoubleArray {
val zone = mutableListOf<List<Int>>()
val r = matrix[0].size / z
for (row in 0 until z) {
for (col in 0 until z) {
val rowStart = row * r
val colStart = col * r
val temp = mutableListOf<Int>()
for (i in 0 until r) {
(0 until r).mapTo(temp) { matrix[rowStart + i][colStart + it] }
}
zone.add(temp)
}
}
val density = mutableListOf<Double>()
zone.forEach { density.add(it.sum() / it.size.toDouble()) }
return density.toDoubleArray()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment