Skip to content

Commit

Permalink
Merge branch 'master' into documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
julianmendez committed Mar 17, 2024
2 parents cc24a9b + 16c7046 commit 725f7b5
Show file tree
Hide file tree
Showing 34 changed files with 1,276 additions and 120 deletions.
7 changes: 7 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ lazy val examples =
.dependsOn(core)
.settings(
commonSettings,
/**
* YAML 1.2 parser
* [[https://bitbucket.org/asomov/snakeyaml-engine]]
* [[https://repo1.maven.org/maven2/org/snakeyaml/snakeyaml-engine/]]
*/
libraryDependencies += "org.snakeyaml" % "snakeyaml-engine" % "2.7",
assembly / assemblyJarName := "examples-" + version.value + ".jar"
)

Expand All @@ -72,6 +78,7 @@ lazy val root =
.dependsOn(docs, core, examples)
.settings(
commonSettings,
assembly / mainClass := Some("soda.tiles.fairness.example.main.EntryPoint"),
assembly / assemblyJarName := "tiles-" + version.value + ".jar"
)

Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,12 @@ import soda.tiles.fairness.tile.FalsePosTile
import soda.tiles.fairness.tile.NeededPTile
import soda.tiles.fairness.tile.PredictionPTile
import soda.tiles.fairness.tile.ReceivedSigmaPTile
import soda.tiles.fairness.tile.ResultPTile
import soda.tiles.fairness.tile.SigmaTile
import soda.tiles.fairness.tile.UnzipPairFstTile
import soda.tiles.fairness.tile.UnzipPairSndTile
import soda.tiles.fairness.tile.UnzipTripleFstTile
import soda.tiles.fairness.tile.UnzipTripleSndTile
import soda.tiles.fairness.tile.UnzipTripleTrdTile
import soda.tiles.fairness.tile.WithPTile
import soda.tiles.fairness.tile.ZipTile


Expand Down Expand Up @@ -190,9 +188,9 @@ trait UnbiasednessPipeline

lazy val prediction_p_tile = PredictionPTile .mk (p0_evaluation)

lazy val result_p_tile = ResultPTile .mk (p1_result)
lazy val result_p_tile = AttributePTile .mk (p1_result)

lazy val with_p_tile = WithPTile .mk (p2_with_p)
lazy val with_p_tile = AttributePTile .mk (p2_with_p)

lazy val false_pos_tile = FalsePosTile .mk

Expand Down
2 changes: 0 additions & 2 deletions core/src/main/scala/soda/tiles/fairness/pipeline/Package.soda
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,11 @@ import
soda.tiles.fairness.tile.NeededPTile
soda.tiles.fairness.tile.PredictionPTile
soda.tiles.fairness.tile.ReceivedSigmaPTile
soda.tiles.fairness.tile.ResultPTile
soda.tiles.fairness.tile.SigmaTile
soda.tiles.fairness.tile.UnzipPairFstTile
soda.tiles.fairness.tile.UnzipPairSndTile
soda.tiles.fairness.tile.UnzipTripleFstTile
soda.tiles.fairness.tile.UnzipTripleSndTile
soda.tiles.fairness.tile.UnzipTripleTrdTile
soda.tiles.fairness.tile.WithPTile
soda.tiles.fairness.tile.ZipTile

Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ class UnbiasednessPipeline

prediction_p_tile = PredictionPTile .mk (p0_evaluation)

result_p_tile = ResultPTile .mk (p1_result)
result_p_tile = AttributePTile .mk (p1_result)

with_p_tile = WithPTile .mk (p2_with_p)
with_p_tile = AttributePTile .mk (p2_with_p)

false_pos_tile = FalsePosTile .mk

Expand Down
57 changes: 0 additions & 57 deletions core/src/main/scala/soda/tiles/fairness/tile/Package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -677,35 +677,6 @@ object ReceivedSigmaPTile {
}


/*
directive lean
import Soda.tiles.fairness.tool.TileMessage
import Soda.tiles.fairness.tile.AttributePTile
*/

/**
* This tile is a particular case of an 'AttributePTile', where the attribute is the 'result'.
* This tile is used to contrast obtained results to predicted results.
*/

trait ResultPTile
{

def p : Actor => Measure

def apply (message : TileMessage [Seq [Actor] ] ) : TileMessage [Seq [Measure] ] =
AttributePTile .mk (p) .apply (message)

}

case class ResultPTile_ (p : Actor => Measure) extends ResultPTile

object ResultPTile {
def mk (p : Actor => Measure) : ResultPTile =
ResultPTile_ (p)
}


/*
directive lean
import Soda.tiles.fairness.tool.TileMessage
Expand Down Expand Up @@ -912,34 +883,6 @@ object UnzipTripleTrdTile {
}


/*
directive lean
import Soda.tiles.fairness.tool.TileMessage
import Soda.tiles.fairness.tile.AttributePTile
*/

/**
* This tile is a particular case of a 'AttributePTile', that projects given property.
*/

trait WithPTile
{

def p : Actor => Measure

def apply (message : TileMessage [Seq [Actor] ] ) : TileMessage [Seq [Measure] ] =
AttributePTile .mk (p) .apply (message)

}

case class WithPTile_ (p : Actor => Measure) extends WithPTile

object WithPTile {
def mk (p : Actor => Measure) : WithPTile =
WithPTile_ (p)
}


/*
directive lean
import Soda.tiles.fairness.tool.TileMessage
Expand Down
20 changes: 0 additions & 20 deletions core/src/main/scala/soda/tiles/fairness/tile/ResultPTile.soda

This file was deleted.

20 changes: 0 additions & 20 deletions core/src/main/scala/soda/tiles/fairness/tile/WithPTile.soda

This file was deleted.

4 changes: 2 additions & 2 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ are:
[ResourceAllocationScenarioExample]: https://github.com/julianmendez/tiles/blob/master/core/src/test/scala/soda/tiles/fairness/pipeline/ResourceAllocationScenarioExample.soda
[EqualityPipelineSpec]: https://github.com/julianmendez/tiles/blob/master/core/src/test/scala/soda/tiles/fairness/pipeline/EqualityPipelineSpec.soda
[EquityPipelineSpec]: https://github.com/julianmendez/tiles/blob/master/core/src/test/scala/soda/tiles/fairness/pipeline/EquityPipelineSpec.soda
[ccs-example]: ccs_example.html
[scoring-example]: scoring_example.html
[ccs-example]: https://julianmendez.github.io/tiles/ccs_example.html
[scoring-example]: https://julianmendez.github.io/tiles/scoring_example.html

<script>
window.mermaid.init(undefined, document.querySelectorAll('.language-mermaid'));
Expand Down
7 changes: 3 additions & 4 deletions docs/scoring_example.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ These are some of the implemented fairness tiles for scoring scenarios:
|:---------------------------------------------------|:---------------------------------------------|
| all-actor <sub>*(a0), (a1), (a2)*</sub> | [AllActorTripleTile][AllActorTripleTile] |
| <sub>*(a)*</sub> prediction <sub>*(m)*</sub> | [PredictionPTile][PredictionPTile] |
| <sub>*(a)*</sub> result <sub>*(m)*</sub> | [ResultPTile][ResultPTile] |
| <sub>*(a)*</sub> result <sub>*(m)*</sub> | [AttributePTile][AttributePTile] |
| <sub>*(m0), (m1)*</sub> false-pos <sub>*(m)*</sub> | [FalsePosTile][FalsePosTile] |
| <sub>*(a)*</sub> with <sub>*(m)*</sub> | [WithPTile][WithPTile] |
| <sub>*(a)*</sub> with <sub>*(m)*</sub> | [AttributePTile][AttributePTile] |
| <sub>*(m0), (m1)*</sub> correlation <sub>*m*</sub> | [CorrelationTile][CorrelationTile] |
| <sub>*m*</sub> decision <sub>*b*</sub> | [DecisionTile][DecisionTile] |
| unbiasedness <sub>*b*</sub> | [UnbiasednessPipeline][UnbiasednessPipeline] |
Expand All @@ -40,9 +40,8 @@ graph LR

[AllActorTripleTile]: https://github.com/julianmendez/tiles/blob/master/core/src/main/scala/soda/tiles/fairness/tile/AllActorTripleTile.soda
[PredictionPTile]: https://github.com/julianmendez/tiles/blob/master/core/src/main/scala/soda/tiles/fairness/tile/PredictionPTile.soda
[ResultPTile]: https://github.com/julianmendez/tiles/blob/master/core/src/main/scala/soda/tiles/fairness/tile/ResultPTile.soda
[AttributePTile]: https://github.com/julianmendez/tiles/blob/master/core/src/main/scala/soda/tiles/fairness/tile/AttributePTile.soda
[FalsePosTile]: https://github.com/julianmendez/tiles/blob/master/core/src/main/scala/soda/tiles/fairness/tile/FalsePosTile.soda
[WithPTile]: https://github.com/julianmendez/tiles/blob/master/core/src/main/scala/soda/tiles/fairness/tile/WithPTile.soda
[CorrelationTile]: https://github.com/julianmendez/tiles/blob/master/core/src/main/scala/soda/tiles/fairness/tile/CorrelationTile.soda
[DecisionTile]: https://github.com/julianmendez/tiles/blob/master/core/src/main/scala/soda/tiles/fairness/tile/DecisionTile.soda
[UnbiasednessPipeline]: https://github.com/julianmendez/tiles/blob/master/core/src/main/scala/soda/tiles/fairness/pipeline/UnbiasednessPipeline.soda
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@

class CcsAcromagatInstance

abstract
actors : Seq [Actor]
resources : Seq [Resource]
outcome : Outcome
actor_children_map : Map [Actor] [Measure]
actor_adults_map : Map [Actor] [Measure]
actor_income_map : Map [Actor] [Measure]
resource_value_map : Map [Resource] [Measure]
pipelines : Seq [String]

_add_value_to (value : Int) (m : Measure) : Measure =
match m
case Some (other_value) ==> Some (value + other_value)
case None ==> None

measure_sum (a : Measure) (b : Measure) : Measure =
match a
case Some (value) ==> _add_value_to (value) (b)
case None ==> None

get_or_else [A : Type] (map : Map [A] [Measure] ) (key : A) (default : Measure) : Measure =
match map .get (key)
case Some (value) ==> value
case None ==> default

actor_children (actor : Actor) : Measure =
get_or_else [Actor] (actor_children_map) (actor) (Some (-1) )

actor_adults (actor : Actor) : Measure =
get_or_else [Actor] (actor_adults_map) (actor) (Some (-1) )

actor_income (actor : Actor) : Measure =
get_or_else [Actor] (actor_income_map) (actor) (Some (-1) )

resource_value (resource : Resource) : Measure =
get_or_else [Resource] (resource_value_map) (resource) (Some (-1) )

context = "ChildCareSubsidy"

initial_message : TileMessage [Boolean] =
TileMessageBuilder .mk .build (context) (outcome) (true)

end

Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@

class CcsAcromagatInstanceBuilder

abstract

import
soda.tiles.fairness.example.parser.YamlParser
java.io.BufferedReader
java.io.Reader

actors_key = "actors"

resources_key = "resources"

outcome_key = "outcome"

actor_children_key = "actor_children"

actor_adults_key = "actor_adults"

actor_income_key = "actor_income"

resource_value_key = "resource_value"

pipelines_key = "pipelines"

to_measure (s : String) : Measure =
s .toIntOption

_get_actors (m : Map [String] [Seq [Tuple2 [String] [String] ] ] )
: Seq [Actor] =
m .getOrElse (actors_key , None)
.iterator
.map (lambda pair --> pair ._1)
.toSeq

_get_resources (m : Map [String] [Seq [Tuple2 [String] [String] ] ] )
: Seq [Resource] =
m .getOrElse (resources_key , None)
.iterator
.map (lambda pair --> pair ._1)
.toSeq

_get_outcome (m : Map [String] [Seq [Tuple2 [String] [String] ] ] )
: Outcome =
Outcome .mk (
m .getOrElse (outcome_key , None)
.iterator
.map(lambda pair --> Assignment .mk (pair._1) (pair ._2) )
.toSeq
)

_get_actor_children_map (m : Map [String] [Seq [Tuple2 [String] [String] ] ] )
: Map [Actor] [Measure] =
m .getOrElse (actor_children_key , None)
.iterator
.map (lambda pair --> Tuple2 (pair ._1 , to_measure (pair ._2) ) )
.toMap

_get_actor_adults_map (m : Map [String] [Seq [Tuple2 [String] [String] ] ] )
: Map [Actor] [Measure] =
m .getOrElse (actor_adults_key , None)
.iterator
.map (lambda pair --> Tuple2 (pair ._1 , to_measure (pair ._2) ) )
.toMap

_get_actor_income_map (m : Map [String] [Seq [Tuple2 [String] [String] ] ] )
: Map [Actor] [Measure] =
m .getOrElse (actor_income_key , None)
.iterator
.map (lambda pair --> Tuple2 (pair ._1 , to_measure (pair ._2) ) )
.toMap

_get_resource_value_map (m : Map [String] [Seq [Tuple2 [String] [String] ] ] )
: Map [Resource] [Measure] =
m .getOrElse (resource_value_key , None)
.iterator
.map (lambda pair --> Tuple2 (pair ._1 , to_measure (pair ._2) ) )
.toMap

_get_pipelines (m : Map [String] [Seq [Tuple2 [String] [String] ] ] )
: Seq [String] =
m .getOrElse (pipelines_key , None)
.iterator
.map (lambda pair --> pair ._1)
.toSeq

_build_from_map (m : Map [String] [Seq [Tuple2 [String] [String] ] ] )
: Option [CcsAcromagatInstance] =
Some (
CcsAcromagatInstance .mk (
_get_actors (m) ) (
_get_resources (m) ) (
_get_outcome (m) ) (
_get_actor_children_map (m) ) (
_get_actor_adults_map (m) ) (
_get_actor_income_map (m) ) (
_get_resource_value_map (m) ) (
_get_pipelines (m)
)
)

build (s : Seq [Seq [Tuple2 [String] [Seq [Tuple2 [String] [String] ] ] ] ] )
: Option [CcsAcromagatInstance] =
match s
case a +: as ==> _build_from_map (a .toMap)
case otherwise ==> None

from_yaml (reader : Reader) : Option [CcsAcromagatInstance] =
build (YamlParser .mk .parse (reader) )

end

Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@

class CcsNoSubsidyPipeline
extends
CcsPipeline

abstract
sigma : Measure -> Measure -> Measure
Expand All @@ -23,4 +25,7 @@ class CcsNoSubsidyPipeline
)
)

runner : TileMessage [Boolean] -> TileMessage [Boolean] =
lambda message --> apply (message)

end
Loading

0 comments on commit 725f7b5

Please sign in to comment.