PyPI package for conversion cost values (less is better) to fitness values (more is better) and vice versa
Project description
cost2fitness
PyPI package for conversion cost values (less is better) to fitness values (more is better) and vice versa
pip install cost2fitness
About
This is the package containing several methods for transformation numpy arrays depended on scales, averages and so on. But the primary way to use it is the conversion from cost values (less is better) to fitness values (more is better) and vice versa. It can be highly helpful when u r using
- evolutionary algorithms depended on numeric differences: so, it's important to set good representation of samples scores for better selection
- sampling methods with probabilities depended on samples scores
Transformers
There are several simple transformers. Each transformer is the subclass of BaseTransformer
class containing name
field and transform(array)
method which transforms input array to new representation.
Checklist:
ReverseByAverage
,AntiMax
,AntiMaxPercent(percent)
,Min2Zero
,Min2Value(value)
,ProbabilityView
(converts data to probabilities),Softmax
,Relu
,SimplestReverse
,AlwaysOnes
(returns array of ones),NewAvgByMult(new_average)
,NewAvgByShift(new_average)
U can create your transformer using simple logic from file.
import numpy as np
from cost2fitness import Min2Zero
tf = Min2Zero()
arr_of_scores = np.array([10, 8, 7, 5, 8, 9, 20, 12, 6, 18])
tf.transform(arr_of_scores)
# array([ 5, 3, 2, 0, 3, 4, 15, 7, 1, 13])
Pipeline of transformers
U also can combine these transformers using Pl
pipeline. For example:
import numpy as np
from cost2fitness import ReverseByAverage, AntiMax, Min2Zero, Pl
pipe = Pl([
Min2Zero(),
ReverseByAverage(),
AntiMax()
])
arr_of_scores = np.array([10, 8, 7, 5, 8, 9])
# return each result of pipeline transformation (with input)
pipe.transform(arr_of_scores, return_all_steps= True)
#array([[10. , 8. , 7. , 5. , 8. ,
# 9. ],
# [ 5. , 3. , 2. , 0. , 3. ,
# 4. ],
# [ 0.66666667, 2.66666667, 3.66666667, 5.66666667, 2.66666667,
# 1.66666667],
# [ 5. , 3. , 2. , 0. , 3. ,
# 4. ]])
# return only result of transformation
pipe.transform(arr_of_scores, return_all_steps= False)
#array([5., 3., 2., 0., 3., 4.])
How to plot
There is plot_scores
function for plotting transformation process results. It has arguments:
scores
: 2D numpy array 2D numpy array with structure[start_values, first_transform(start_values), second_transform(first_transform), ...]
, where each object is 1D-array of scores (values/costs/fitnesses).names
:None
/string list, optional Names for each step for plot labels. The default isNone
.kind
: str, optional for 'beside' each new column will be beside previous; for 'under' there will be new plot under previous. The default is 'beside'.save_as
:None
/str, optional File path to save the plot. The default isNone
.
Examples
Each transformer
Pipeline
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for cost2fitness-1.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e1544197399f7fdf38b2433efa7c719683ae0d775446013e0be1b35e36867879 |
|
MD5 | 7126eb8908b751374898ff5f5d958c3c |
|
BLAKE2b-256 | 6389641de72fca93bb7bacec7c4103696888dabc68c1ee4f5c6f19ee24536c97 |