Ejemplo n.º 1
0
 def __init__(self, data, param):
     self.param = param
     self.differ = Differential(self.param.Seed)
     # ## initialize the root
     self.root = KNode()
     self.root.n_data = data
     self.root.n_box = np.array([Params.LOW, Params.HIGH])
     self.root.n_budget = Params.maxHeight
Ejemplo n.º 2
0
 def __init__(self, data, param):
     self.param = param
     self.differ = Differential(self.param.Seed)
     self.mapp = None
     self.root = KNode()
     self.realData = data
     self.root.n_box = None
     self.root.n_budget = Params.maxHeight
Ejemplo n.º 3
0
    def __init__(self, data, param):
        self.param = param
        self.differ = Differential(self.param.Seed)

        # initialize the root
        self.root = Node()
        # self.children = [] # all level 2 grids
        self.root.n_data = data
        self.root.n_box = np.array([param.LOW, param.HIGH])
Ejemplo n.º 4
0
    def __init__(self, data, eps, param, firstGrid=None, use_domain_knowledge=None):
        """
        two levels grid
        """
        self.eps = eps
        self.first = False
        self.DOMAIN_KNOWLEDGE = use_domain_knowledge

        if firstGrid is None:
            # this first grid --> need to construct
            self.first = True
            Grid_adaptiveM.__init__(self, data, eps, param, self.DOMAIN_KNOWLEDGE)
        else:
            self.param = param
            self.differ = Differential(self.param.Seed)

            # update root
            self.root = copy.deepcopy(firstGrid.root)
            self.root.n_data = data
    def __init__(self, param):
        """
        generated source for method __init__
        """
        Parser.__init__(self)

        self.param = param
        self.differ = Differential(self.param.Seed)

        self.predict = []
        self.interval = None

        # Kalman Filter params
        self.P = 100

        # estimation error covariance (over all time instance)
        self.Q = 1000

        # process noise synthetic data
        self.R = 1000000

        # measurement noise optimal for alpha = 1, synthetic data
        self.K = 0

        # kalman gain
        # PID control params - default
        self.Cp = 0.9  # proportional gain, to keep output proportional to current error
        self.Ci = 0.1  # integral gain, to eliminate offset
        self.Cd = 0.0  # derivative gain, to ensure stability - prevent large error in future

        # fixed internally
        self.theta = 1  # magnitude of changes
        self.xi = 0.2  # gamma (10%)
        self.minIntvl = 1  # make sure the interval is greater than 1

        self.windowPID = 5  # I(integration) window
        self.ratioM = 0.2  # sampling rate

        #
        self.isSampling = False
Ejemplo n.º 6
0
        r, theta = [
            math.sqrt(random.uniform(0, 1)) * math.sqrt(1),
            2 * math.pi * random.uniform(0, 1)
        ]
        y = [math.cos(theta) * r, math.sin(theta) * r]
        d = dist(x, y)
        total += d

    print("Expected dist: ", total / N)
"""
Simulated dataset
"""
p = Params(1000)
p.select_dataset()
reachable_range = Utils.reachableDistance()
dp = Differential(p.seed)

# Randomly picking location in a small MBR of tdrive dataset.
minLat, maxLat = 39.1232147, 40.7225952
minLon, maxLon = 115.3879166, 117.3795395

diffLat = maxLat - minLat
diffLon = maxLon - minLon

maxLat = maxLat - 0.95 * diffLat
maxLon = maxLon - 0.95 * diffLon

# print ("diagonal dist: ", Utils.distance(minLat, minLon, maxLat, maxLon))


def probs_from_sampling(samples, step, d_prime_values, d_matches_values):
Ejemplo n.º 7
0
def test_privateMedian():
    f = open(res_dir + 'privateMedian', 'w')
    f_t = open(res_dir + 'privateMedian-time', 'w')
    data = np.sort(dataGen.data_gen(dist, NDIM, LO, HI, NDATA)).flatten()
    n = len(data)

    for i in range(10):
        print 'level ' + ` i `
        container = np.zeros(6)
        container_t = np.zeros(6)
        for seed in seed_list:
            perturber = Differential(seed)
            for j in range(2**i):
                c_data = data[n * j / 2**i:n * (j + 1) / 2**i]
                c_len = len(c_data)

                # exponential mechanism
                start = time.clock()
                em = perturber.getSplit_exp(c_data, c_data[0], c_data[-1], eps,
                                            1)
                end = time.clock()
                container_t[0] += end - start
                # smooth sensitivity (2-approx)
                start = time.clock()
                ls = perturber.getSplit_smooth(c_data, c_data[0], c_data[-1],
                                               eps, 1)
                end = time.clock()
                container_t[1] += end - start
                # exponential mechanism sampling
                start = time.clock()
                em_samp = perturber.getSplit_exp(c_data, c_data[0], c_data[-1],
                                                 eps, srt)
                end = time.clock()
                container_t[2] += end - start
                # smooth sensitivity sampling
                start = time.clock()
                ls_samp = perturber.getSplit_smooth(c_data, c_data[0],
                                                    c_data[-1], eps, srt)
                end = time.clock()
                container_t[3] += end - start
                # noisy mean approximation
                start = time.clock()
                nm = perturber.getSplit_noisyMean(c_data, c_data[0],
                                                  c_data[-1], eps)
                end = time.clock()
                container_t[4] += end - start
                # noisy grid approximation
                start = time.clock()
                ng = perturber.getSplit_grid(c_data, c_data[0], c_data[-1],
                                             eps, unit)
                end = time.clock()
                container_t[5] += end - start

                res = [em, ls, em_samp, ls_samp, nm, ng]
                for k in range(6):
                    if res[k] >= c_data[-1] or res[k] <= c_data[0]:
                        container[k] += 1.0
                    else:
                        r_k = np.searchsorted(c_data, res[k])
                        r_m = float(c_len) / 2
                        container[k] += abs(r_m - r_k) / r_m
                        # end of j loop
        for k in range(6):
            f.write( ` container[k] / (2**i * len(seed_list)) ` + ' ')
        f.write('\n')
        for k in range(6):
            f_t.write( ` container_t[k] / (2**i * len(seed_list)) ` + ' ')
        f_t.write('\n')
    # end of i
    f.close()
    f_t.close()
Ejemplo n.º 8
0
def main():

    #
    # Need to parse command line arguements first, because PyROOT is going
    # to muck up the usage as soon as a root class is loaded.
    #
    parser = OptionParser()
    parser.add_option("-b",
                      "--base",
                      dest="baseline",
                      help="Set the baseline geometry [required]",
                      metavar="BASE",
                      default="NONE")
    parser.add_option("-g",
                      "--geom",
                      dest="geometry",
                      help="Set the comparison geometry [required]",
                      metavar="GEOM",
                      default="NONE")

    parser.add_option(
        "--basename",
        dest="basename",
        help=
        "Set the name of the baseline geometry if different from base [optional]",
        metavar="BASENAME",
        default="same")
    parser.add_option(
        "--geomname",
        dest="geomname",
        help=
        "Set the name of the comparsion geometry if different from geom [optional]",
        metavar="GEOMNAME",
        default="same")

    parser.add_option("-v",
                      "--volume",
                      dest="volume",
                      help="Set the top level volume [required]",
                      metavar="VOLUME",
                      default="CAVE")
    parser.add_option("--basepath", dest="basepath", default="NONE")
    parser.add_option("--geompath", dest="geompath", default="NONE")

    parser.add_option("--stat",
                      dest="stat",
                      default="radlen",
                      help="Statistic to display")

    parser.add_option(
        "--thumbnail",
        dest="thumbnail",
        default=False,
        action="store_true",
        help="Creates thumbnails of the front page of the PDF file.")
    parser.add_option("--size",
                      dest="size",
                      default=False,
                      help="Sets the size of the thumbnail, e.g. 850x1100")

    (opts, args) = parser.parse_args()

    if (opts.baseline == "NONE"):
        print ""
        print "Must specify a baseline geometry."
        print ""
        os.system("./differential.py --help")
        return

    if (opts.geometry == "NONE"):
        print ""
        print "Must specify a comparison geometry."
        print ""
        os.system("./differential.py --help")
        return

    from Differential import Differential, _file_path
    from Differential import get_geom_file
    from Canvas import CanvasPDF

    from ROOT import TFile
    from ROOT import TGeoManager
    from ROOT import TGeoVolume
    from ROOT import TGeoNode

    from ROOT import kWhite
    from ROOT import gStyle

    gStyle.SetHistMinimumZero()
    gStyle.SetCanvasColor(kWhite)

    # Setup temporary symbolic links to the root files
    if (opts.basepath != "NONE"):
        os.system("ln -s " + opts.basepath + "/" + opts.baseline + ".root .")
    if (opts.geompath != "NONE"):
        os.system("ln -s " + opts.geompath + "/" + opts.geometry + ".root .")

    canvas = CanvasPDF(name="differential-" + opts.baseline + "-vs-" +
                       opts.geometry + "-" + opts.volume,
                       title="Geometry differential for volume=" +
                       opts.volume + " " + opts.baseline + " vs " +
                       opts.geometry,
                       nx=1,
                       ny=1,
                       thumbnail=opts.thumbnail)

    differ = Differential(base=opts.baseline,
                          comp=opts.geometry,
                          top=opts.volume,
                          basegeo=opts.basename,
                          compgeo=opts.geomname,
                          canvas=canvas,
                          stat=opts.stat)

    # Remove temporary symbolic links to the root files
    if (opts.basepath != "NONE"):
        os.system("rm " + opts.basepath + "/" + opts.baseline + ".root")
    if (opts.geompath != "NONE"):
        os.system("rm " + opts.geompath + "/" + opts.geometry + ".root")