start on moving lin alg functions over

This commit is contained in:
Rowan Torbitzky-Lane 2025-03-06 14:32:10 -06:00
parent 0d590bd259
commit d59812b0fb

View File

@ -1,13 +1,13 @@
module HushGP.Instructions.GenericInstructions where module HushGP.Instructions.GenericInstructions where
import Control.Lens import Control.Lens
import HushGP.State
import HushGP.Instructions.Utility
import Data.List (sort, sortBy) import Data.List (sort, sortBy)
import Data.Ord import Data.Ord
import Data.List.Split import Data.List.Split
import Numeric.LinearAlgebra (vector, norm_2)
-- import Debug.Trace import Numeric.Statistics.Moment
import HushGP.State
import HushGP.Instructions.Utility-- import Debug.Trace
-- |Does No Operation. Useful for genome stuff :) -- |Does No Operation. Useful for genome stuff :)
instructionNoOpBlock :: State -> State instructionNoOpBlock :: State -> State
@ -564,3 +564,11 @@ instructionVectorInsertVector accessor state@(State {_int = i1 : is}) =
state{_int = is} & accessor .~ (combineTupleList v2 (splitAt (fromIntegral i1) v1) : vs) state{_int = is} & accessor .~ (combineTupleList v2 (splitAt (fromIntegral i1) v1) : vs)
_ -> state _ -> state
instructionVectorInsertVector _ state = state instructionVectorInsertVector _ state = state
-- |Takes a numeric vector lens and a primitive lens. Pushes the mean of the top
-- vector to the primitive stack.
instructionVectorMean :: Fractional a => Lens' State [a] -> Lens' State [[a]] -> (b -> a) -> State -> State
instructionVectorMean primAccessor vectorAccessor wrangleFunc state =
case uncons (view vectorAccessor state) of
Just (v1, vs) -> state & vectorAccessor .~ vs & primAccessor .~ (mean v1 : view primAccessor state)
_ -> state