Esempio n. 1
0
    def defaultColor():
        """Default color distribution for cars.

		The distribution starts with a base distribution over 9 discrete colors,
		then adds Gaussian HSL noise. The base distribution uses color popularity
		statistics from a `2012 DuPont survey`_.

		.. _2012 DuPont survey: https://web.archive.org/web/20121229065631/http://www2.dupont.com/Media_Center/en_US/color_popularity/Images_2012/DuPont2012ColorPopularity.pdf
		"""
        baseColors = {
            (248, 248, 248): 0.24,  # white
            (50, 50, 50): 0.19,  # black
            (188, 185, 183): 0.16,  # silver
            (130, 130, 130): 0.15,  # gray
            (194, 92, 85): 0.10,  # red
            (75, 119, 157): 0.07,  # blue
            (197, 166, 134): 0.05,  # brown/beige
            (219, 191, 105): 0.02,  # yellow/gold
            (68, 160, 135): 0.02,  # green
        }
        converted = {
            CarColor.withBytes(color): prob
            for color, prob in baseColors.items()
        }
        baseColor = Options(converted)
        # TODO improve this?
        hueNoise = Normal(0, 0.1)
        satNoise = Normal(0, 0.1)
        lightNoise = Normal(0, 0.1)
        return NoisyColorDistribution(baseColor, hueNoise, satNoise,
                                      lightNoise)
Esempio n. 2
0
def test_distribution_method_encapsulation_lazy():
    vf = VectorField("Foo", lambda pos: 0)
    da = DelayedArgument(set(), lambda context: Options([1, 2]))
    pt = vf.followFrom(Vector(0, 0), da, steps=1)
    assert isinstance(pt, DelayedArgument)
    evpt = valueInContext(pt, {})
    assert not needsLazyEvaluation(evpt)
    assert isinstance(evpt, VectorMethodDistribution)
    assert evpt.method is underlyingFunction(vf.followFrom)
Esempio n. 3
0
    'Following',
    # Constants
    'everywhere',
    'nowhere',
    # Temporary stuff... # TODO remove
    'PropertyDefault')

# various Python types and functions used in the language but defined elsewhere
from scenic.core.geometry import sin, cos, hypot, max, min
from scenic.core.vectors import Vector, VectorField, PolygonalVectorField
from scenic.core.regions import (Region, PointSetRegion, RectangularRegion,
                                 PolygonalRegion, PolylineRegion, everywhere,
                                 nowhere)
from scenic.core.workspaces import Workspace
from scenic.core.distributions import Range, Options, Normal
Uniform = lambda *opts: Options(opts)  # TODO separate these?
Discrete = Options
from scenic.core.external_params import (VerifaiParameter, VerifaiRange,
                                         VerifaiDiscreteRange, VerifaiOptions)
from scenic.core.object_types import Mutator, Point, OrientedPoint, Object
from scenic.core.specifiers import PropertyDefault  # TODO remove

# everything that should not be directly accessible from the language is imported here:
import inspect
from scenic.core.distributions import Distribution, toDistribution
from scenic.core.type_support import isA, toType, toTypes, toScalar, toHeading, toVector
from scenic.core.type_support import evaluateRequiringEqualTypes, underlyingType
from scenic.core.geometry import RotatedRectangle, normalizeAngle, apparentHeadingAtPoint
from scenic.core.object_types import Constructible
from scenic.core.specifiers import Specifier
from scenic.core.lazy_eval import DelayedArgument
Esempio n. 4
0
 def defaultModel(self):
     return Options(self.modelProbs)
Esempio n. 5
0
 def uniformModel(self):
     return Options(self.modelProbs.keys())
Esempio n. 6
0
def test_distribution_method_encapsulation():
    vf = VectorField("Foo", lambda pos: 0)
    pt = vf.followFrom(Vector(0, 0), Options([1, 2]), steps=1)
    assert isinstance(pt, VectorMethodDistribution)
    assert pt.method is underlyingFunction(vf.followFrom)
Esempio n. 7
0
def test_pickle_distribution():
    dist = Options({
        Range(0, 1): 2,
        Options([12 + Range(-1, 3), Range(4, 5)]): 1
    })
    tryPickling(dist)
Esempio n. 8
0
def test_bucketed_options():
    o = Options({0: 1, 1: 3})
    similarDistributions(o, o.bucket())