forked from anyoptimization/pymoo
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
19 changed files
with
1,107 additions
and
118 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,8 +10,6 @@ __pycache__/ | |
*.so | ||
|
||
|
||
pymoo/experimental/* | ||
|
||
|
||
pymoo/cython/*html | ||
|
||
|
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,47 @@ | ||
# distutils: language = c++ | ||
# cython: boundscheck=False, wraparound=False, cdivision=True | ||
|
||
|
||
from my_math cimport c_norm | ||
from libcpp.vector cimport vector | ||
|
||
|
||
def cython_pbi(double[:,:] F, double[:] weights, double[:] ideal_point, double theta=0.01): | ||
return c_pbi(F, weights, ideal_point, theta) | ||
|
||
|
||
|
||
cdef extern from "math.h": | ||
double sqrt(double m) | ||
double pow(double base, double exponent) | ||
|
||
|
||
cdef vector[double] c_pbi(double[:,:] F, double[:] weights, double[:] ideal_point, double theta=0.01): | ||
cdef: | ||
double d1, d2, f_max, norm | ||
int i, j, n_dim | ||
vector[double] pbi | ||
|
||
n_points = F.shape[0] | ||
n_obj = F.shape[1] | ||
|
||
pbi = vector[double](n_points) | ||
norm = c_norm(weights) | ||
|
||
for i in range(n_points): | ||
|
||
d1 = 0 | ||
for j in range(n_obj): | ||
d1 += pow(((F[i,j] - ideal_point[j]) * weights[j]) / norm, 2.0) | ||
d1 = sqrt(d1) | ||
|
||
d2 = 0 | ||
for j in range(n_obj): | ||
d2 += pow(F[i,j] - (ideal_point[j] - d1 * weights[j]), 2.0) | ||
d2 = sqrt(d2) | ||
|
||
pbi[i] = d1 + theta * d2 | ||
|
||
return pbi | ||
|
||
|
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,6 @@ | ||
# distutils: language = c++ | ||
# cython: boundscheck=False, wraparound=False, cdivision=True | ||
|
||
|
||
cdef double c_norm(double[:] v) | ||
cdef double[:,:] c_calc_perpendicular_distance(double[:,:] P, double[:,:] L) |
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,68 @@ | ||
# distutils: language = c++ | ||
# cython: boundscheck=False, wraparound=False, cdivision=True | ||
|
||
|
||
import numpy as np | ||
from libcpp.vector cimport vector | ||
|
||
|
||
|
||
def cython_calc_perpendicular_distance(double[:,:] P, double[:,:] L): | ||
return np.array(c_calc_perpendicular_distance(P, L)) | ||
|
||
|
||
|
||
cdef extern from "math.h": | ||
double sqrt(double m) | ||
double pow(double base, double exponent) | ||
|
||
|
||
cdef double c_norm(double[:] v): | ||
cdef: | ||
double val | ||
int i | ||
val = 0 | ||
for i in range(v.shape[0]): | ||
val += pow(v[i], 2) | ||
val = sqrt(val) | ||
return val | ||
|
||
|
||
cdef double[:,:] c_calc_perpendicular_distance(double[:,:] P, double[:,:] L): | ||
cdef : | ||
int s_L, s_P, n_dim, i, j, k | ||
double[:,:] M | ||
vector[double] N | ||
double norm, dot, perp_dist, norm_scalar_proj | ||
|
||
s_L = L.shape[0] | ||
s_P = P.shape[0] | ||
n_dim = L.shape[1] | ||
|
||
M = np.zeros((s_P, s_L), dtype=np.float64) | ||
|
||
for i in range(s_L): | ||
|
||
norm = c_norm(L[i, :]) | ||
|
||
N = vector[double](n_dim) | ||
for k in range(n_dim): | ||
N[k] = L[i, k] / norm | ||
|
||
for j in range(s_P): | ||
|
||
dot = 0 | ||
for k in range(n_dim): | ||
dot += L[i, k] * P[j, k] | ||
norm_scalar_proj = dot / norm | ||
|
||
perp_dist = 0 | ||
for k in range(n_dim): | ||
perp_dist += pow(norm_scalar_proj * N[k] - P[j, k], 2) | ||
perp_dist = sqrt(perp_dist) | ||
|
||
M[j, i] = perp_dist | ||
|
||
return M | ||
|
||
|
Oops, something went wrong.