genericize int mean
This commit is contained in:
parent
b74b43a9c0
commit
67ed23d9ca
@ -1,7 +1,6 @@
|
|||||||
{-# LANGUAGE TemplateHaskell #-}
|
{-# LANGUAGE TemplateHaskell #-}
|
||||||
module HushGP.Instructions.VectorIntInstructions where
|
module HushGP.Instructions.VectorIntInstructions where
|
||||||
|
|
||||||
import Numeric.LinearAlgebra
|
|
||||||
import HushGP.Instructions.GenericInstructions
|
import HushGP.Instructions.GenericInstructions
|
||||||
import HushGP.State
|
import HushGP.State
|
||||||
import HushGP.TH
|
import HushGP.TH
|
||||||
@ -334,14 +333,10 @@ instructionVectorIntInsertVectorInt :: State -> State
|
|||||||
instructionVectorIntInsertVectorInt = instructionVectorInsertVector vectorInt
|
instructionVectorIntInsertVectorInt = instructionVectorInsertVector vectorInt
|
||||||
|
|
||||||
-- |Takes the mean of the top int vector and pushes the rounded int value
|
-- |Takes the mean of the top int vector and pushes the rounded int value
|
||||||
-- to the int stack. No way to easily make this generic.
|
-- to the int stack.
|
||||||
instructionVectorIntMean :: State -> State
|
instructionVectorIntMean :: State -> State
|
||||||
instructionVectorIntMean state@(State {_int = is, _vectorInt = v1 : vs}) = state{_int = mean v1 : is, _vectorInt = vs}
|
instructionVectorIntMean state@(State {_vectorInt = [] : vs}) = instructionVectorFuncVectorToPrim int vectorInt retZero state
|
||||||
where
|
instructionVectorIntMean state = instructionVectorFuncVectorToPrim int vectorInt (\xs -> round $ sum (map (fromIntegral @Integer @Double) xs) / fromIntegral @Int @Double (length xs)) state
|
||||||
mean :: [Integer] -> Integer
|
|
||||||
mean [] = 0
|
|
||||||
mean xs = round $ sum (map (fromIntegral @Integer @Double) xs) / fromIntegral @Int @Double (length xs)
|
|
||||||
instructionVectorIntMean state = state
|
|
||||||
|
|
||||||
-- |Takes the maximum of the top int vector and pushes the int value
|
-- |Takes the maximum of the top int vector and pushes the int value
|
||||||
-- to the int stack.
|
-- to the int stack.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user