Skip to content

Instantly share code, notes, and snippets.

View pablormier's full-sized avatar

Pablo R. Mier pablormier

View GitHub Profile
@pablormier
pablormier / wine.csv
Created September 26, 2018 18:46
UCI Wine Dataset
Wine Alcohol Malic.acid Ash Acl Mg Phenols Flavanoids Nonflavanoid.phenols Proanth Color.int Hue OD Proline
1 14.23 1.71 2.43 15.6 127 2.8 3.06 .28 2.29 5.64 1.04 3.92 1065
1 13.2 1.78 2.14 11.2 100 2.65 2.76 .26 1.28 4.38 1.05 3.4 1050
1 13.16 2.36 2.67 18.6 101 2.8 3.24 .3 2.81 5.68 1.03 3.17 1185
1 14.37 1.95 2.5 16.8 113 3.85 3.49 .24 2.18 7.8 .86 3.45 1480
1 13.24 2.59 2.87 21 118 2.8 2.69 .39 1.82 4.32 1.04 2.93 735
1 14.2 1.76 2.45 15.2 112 3.27 3.39 .34 1.97 6.75 1.05 2.85 1450
1 14.39 1.87 2.45 14.6 96 2.5 2.52 .3 1.98 5.25 1.02 3.58 1290
1 14.06 2.15 2.61 17.6 121 2.6 2.51 .31 1.25 5.05 1.06 3.58 1295
1 14.83 1.64 2.17 14 97 2.8 2.98 .29 1.98 5.2 1.08 2.85 1045
@pablormier
pablormier / differential_evolution.py
Last active March 12, 2024 16:59
Small and efficient implementation of the Differential Evolution algorithm using the rand/1/bin schema
import numpy as np
def de(fobj, bounds, mut=0.8, crossp=0.7, popsize=20, its=1000):
dimensions = len(bounds)
pop = np.random.rand(popsize, dimensions)
min_b, max_b = np.asarray(bounds).T
diff = np.fabs(min_b - max_b)
pop_denorm = min_b + pop * diff
fitness = np.asarray([fobj(ind) for ind in pop_denorm])
best_idx = np.argmin(fitness)
@pablormier
pablormier / dijkstra-graph-search-hipster.java
Last active March 16, 2017 01:35
Directed graph shortest path with Dijkstra and Java
// Create a simple weighted directed graph with Hipster where
// vertices are Strings and edge values are just doubles
HipsterDirectedGraph<String,Double> graph =
GraphBuilder.<String,Double>create()
.connect("A").to("B").withEdge(4d)
.connect("A").to("C").withEdge(2d)
.connect("B").to("C").withEdge(5d)
.connect("B").to("D").withEdge(10d)
.connect("C").to("E").withEdge(3d)
.connect("D").to("F").withEdge(11d)
@pablormier
pablormier / multiobjective-graph.graphml
Last active August 29, 2015 14:05
Multiobjective Graph
<?xml version='1.0' encoding='UTF-8'?>
<graphml xmlns="http://graphml.graphdrawing.org/xmlns" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns http://graphml.graphdrawing.org/xmlns/1.1/graphml.xsd">
<key id="c1" for="edge" attr.name="c1" attr.type="int" />
<key id="c2" for="edge" attr.name="c2" attr.type="int" />
<graph id="G" edgedefault="directed">
<node id="v1" />
<node id="v5" />
<node id="v6" />
<node id="v4" />
<node id="v3" />
#!/bin/sh
cd /tmp
wget https://oss.sonatype.org/service/local/repositories/releases/content/es/usc/citius/hipster/hipster-all/1.0.0-rc2/hipster-all-1.0.0-rc2.jar
java -cp hipster-all-1.0.0-rc2.jar es.usc.citius.hipster.examples.ASCIIMazeVisualizer
@pablormier
pablormier / hipster-bibtex.bib
Last active August 29, 2015 14:02
Hipster BibTeX citation entry
@inproceedings{RodriguezMier2014,
author = {Rodriguez-Mier, Pablo and Gonzalez-Sieira, Adrian and Mucientes, Manuel and and Lama, Manuel and Bugarin, Alberto},
booktitle = {9th Iberian Conference on Information Systems and Technologies (CISTI 2014)},
month = jun,
volume = 1,
title = {{Hipster: An Open Source Java Library for Heuristic Search}},
pages = {481--486},
isbn = "978-989-98434-2-4"
address = "Barcelona",
year = {2014}
@pablormier
pablormier / HipsterEightPuzzleExample.java
Last active August 29, 2015 14:02
Solving the 8-Puzzle problem with Hipster
/*
* Copyright 2014 CITIUS <http://citius.usc.es>, University of Santiago de Compostela.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
enum Action { UP, DOWN, LEFT, RIGHT }
Hipster.SearchProblem p =
ProblemBuilder.create()
.initialState(Arrays.asList(5,4,0,7,2,6,8,1,3))
.defineProblemWithExplicitActions()
.useActionFunction( (state) -> return validMovementsFor(state) )
.useTransitionFunction( (action, state) -> applyActionToState(action, state) )
.useCostFunction( (transition) -> return 1d )
.build();
enum Action { UP, DOWN, LEFT, RIGHT }
Hipster.SearchProblem p =
ProblemBuilder.create()
.initialState(Arrays.asList(5,4,0,7,2,6,8,1,3))
.defineProblemWithExplicitActions()
.useActionFunction(new ActionFunction<Action, List<Integer>>() {
public Iterable<Action> actionsFor(List<Integer> board) {
return validMovements(board);
}
// Builder example with Hipster
Hipster.SearchProblem p =
ProblemBuilder.create()
.initialState(initialState)
.defineProblemWithExplicitActions()
.useActionFunction(af)
.useTransitionFunction(atf)
.useCostFunction(cf)
.useHeuristicFunction(hf)
.build();