Skip to content

CSV Example#294

Merged
gpampara merged 10 commits intociren:masterfrom
KyleErwin:CSVExample
Aug 10, 2018
Merged

CSV Example#294
gpampara merged 10 commits intociren:masterfrom
KyleErwin:CSVExample

Conversation

@KyleErwin
Copy link
Copy Markdown
Contributor

An example showcasing how a user could compare multiple algorithms across multiple benchmarks and output the results to some file format such as csv. There are also step by step comments to guide the user
through the example.

@KyleErwin KyleErwin requested a review from gpampara as a code owner August 9, 2018 14:55
simulation(ackley, ackleyStream),
simulation(quadric, quadricStream),
simulation(spherical, sphericalStream)
).flatten
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although flatten does make sense, I'd prefer us to use List.concat here to make the intention that little bit clearer

case Infeasible(_, _) => Double.PositiveInfinity
case Adjusted(_, _) => Double.PositiveInfinity
}
case Multi(_) => Double.PositiveInfinity
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really want these cases hidden from the user in order to prevent people using the holes that scala allows to change this data. The Position is a very important structure for CIlib, so I would actually suggest that we allow this access only via a lens. The crux at the end of the day would be that the if the fitness is a feasible value, we get that otherwise we return the PositiveInfinity value.

This can be done with:

Lenses._singleFitness[Double].composePrism(Lenses._feasible)

which results in an Optional[Position[Double], Double]. The optic can then be used (via getOption) to get the value within an Option which we can then getOrElse(Double.PositiveInfinity) on.

val feasibleOptic = Lenses._singleFitness[Double].composePrism(Lenses._feasible)
val fitnessValues = collection.map(x => feasibleOptic.getOption(x).getOrElse(Double.PositiveInfinity))

import spire.implicits._
import spire.math.Interval

object CSVExample extends SafeApp {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should perhaps make this more generic (the name of the object). The reason being that the only difference between this example and the one that uses the parquet output is the sink used on line 135.

swarm,
Runner.staticAlgorithm("LBestPSO", lbestIter),
stream,
onChange)
Copy link
Copy Markdown
Member

@gpampara gpampara Aug 9, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps remove some duplication?

List(
  Runner.staticAlgorithm("GBestPSO", gbestIter),
  Runner.staticAlgorithm("LBestPSO", lbestIter))
    .map(alg => Runner.foldStep(env,
                      rng,
                      swarm,
                      alg,
                      stream,
                      onChange))

@gpampara
Copy link
Copy Markdown
Member

gpampara commented Aug 9, 2018

Looks good otherwise 👍

gpampara
gpampara previously approved these changes Aug 10, 2018
The resulting optic is now a `Fold` and not an `Optional`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants