-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
068ea3e
commit 52fb045
Showing
13 changed files
with
117 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package gago | ||
|
||
type DistanceMemoizer struct { | ||
Metric func(a, b Genome) float64 | ||
Distances map[Genome]map[Genome]float64 | ||
} | ||
|
||
func makeDistanceMemoizer(metric func(a, b Genome) float64) DistanceMemoizer { | ||
return DistanceMemoizer{ | ||
Metric: metric, | ||
Distances: make(map[Genome]map[Genome]float64), | ||
} | ||
} | ||
|
||
func (dm *DistanceMemoizer) getDistance(a, b Genome) float64 { | ||
if dist, ok := dm.Distances[a][b]; ok { | ||
return dist | ||
} | ||
if dist, ok := dm.Distances[b][a]; ok { | ||
return dist | ||
} | ||
var dist = dm.Metric(a, b) | ||
dm.Distances[a][b] = dist | ||
dm.Distances[b][a] = dist | ||
return dist | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package gago | ||
|
||
import ( | ||
"math" | ||
"testing" | ||
) | ||
|
||
func L1Distance(x1, x2 Genome) (dist float64) { | ||
var g1 = x1.(Vector) | ||
var g2 = x2.(Vector) | ||
for i := range g1 { | ||
dist += math.Abs(g1[i] - g2[i]) | ||
} | ||
return | ||
} | ||
|
||
func TestDistanceMemoizer(t *testing.T) { | ||
var dm = makeDistanceMemoizer(L1Distance) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters