def main(argv):
  if len(argv) > 1:
    raise app.UsageError("Too many command-line arguments.")

  if not os.path.exists(FLAGS.vars_file):
    raise ValueError("No data found at %s" % FLAGS.vars_file)

  if not os.path.exists(FLAGS.save_dir):
    os.mkdir(FLAGS.save_dir)

  ds = dataset_threetone.MaskingDataset()
  for filename in os.listdir(FLAGS.data_path):
    if filename.startswith("masker") and filename.endswith(".txt"):
      ds.read_data(FLAGS.data_path, filename)

  model_class = model.FullModel()
  model_class.initialize_models(FLAGS.vars_file)
  total_error = 0
  total_points = 0
  baseline_error = 0
  for example in ds.get_all_data():
    prediction = model_class.predict(example["masker_frequency"],
                                     example["probe_level"],
                                     example["masker_level"],
                                     example["probe_frequency_bark"])
    error = (example["target_bel_masking"] - prediction)**2
    baseline_error += (example["target_bel_masking"] - 0)**2
    total_error += error
    total_points += 1
  print("Baseline Mean squared error: {}".format(baseline_error / total_points))
  print("Mean squared error: {}".format(total_error / total_points))
  if FLAGS.plot_all_curves:
    plot_all_learned_curves(ds,
                            [1370.0],
                            [30],
                            [80],
                            model_class,
                            FLAGS.save_dir)
  if FLAGS.plot_ood_curves:
    mask_frequencies = [1370.0]
    probe_levels = [30]
    mask_levels = [80]
    plot_all_learned_curves(ds, mask_frequencies, probe_levels, mask_levels,
                            model_class, FLAGS.save_dir)
Exemple #2
0
def main(argv):
  if len(argv) > 1:
    raise app.UsageError("Too many command-line arguments.")

  if not os.path.exists(FLAGS.vars_file):
    raise ValueError("No data found at %s" % FLAGS.vars_file)

  if not os.path.exists(FLAGS.infile_path):
    raise ValueError("No data found at %s" % FLAGS.infile_path)

  if not os.path.exists(FLAGS.save_dir):
    os.mkdir(FLAGS.save_dir)

  with open(FLAGS.infile_path, "r") as infile:
    data = json.load(infile)

  model_class = model.FullModel()
  model_class.initialize_models(FLAGS.vars_file)
  total_error = 0
  total_points = 0
  for example in data:
    probe_frequency_khz = example["probe_frequency"] / 1000
    prediction = model_class.predict(example["masker_frequency"],
                                     example["probe_level"],
                                     example["masker_level"],
                                     probe_frequency_khz)
    predicted_perceived_level = example["probe_level"] - (prediction * 10)
    print("For masker f {}, masker level {}, probe f {}, probe level {}\n Predicted: {}".format(
        example["masker_frequency"], example["masker_level"],
        example["probe_frequency"], example["probe_level"],
        predicted_perceived_level))
    example["perceived_probe_levels"].append(int(predicted_perceived_level))
    total_points += 1

  with open(os.path.join(FLAGS.data_path, "predicted_extra_train_set.json"),
            "w") as outfile:
    json.dump(data, outfile, indent=4)
Exemple #3
0
def main(argv):
  if len(argv) > 1:
    raise app.UsageError("Too many command-line arguments.")

  if not os.path.exists(FLAGS.vars_file):
    raise ValueError("No data found at %s" % FLAGS.vars_file)

  if not os.path.exists(FLAGS.save_dir):
    os.mkdir(FLAGS.save_dir)

  ds = dataset.MaskingDataset()
  for filename in os.listdir(FLAGS.data_path):
    if filename.startswith("masker") and filename.endswith(".txt"):
      ds.read_data(FLAGS.data_path, filename)


  ds_two = []
  with open("predictions.txt", "r") as infile:
    lines = infile.readlines()
    for i, line in enumerate(lines):
      if i == 0:
        continue
      splitted_line = line.split(";")
      frequencies = splitted_line[0].split(",")
      masker_frequency = float(frequencies[0])
      probe_frequency = float(frequencies[1])
      levels = splitted_line[1].split(",")
      masker_level = float(levels[0])
      probe_level = float(levels[1])
      target_bel_masking = float(splitted_line[5]) / 10
      ds_two.append({
          "probe_frequency": probe_frequency,
          "masker_frequency": masker_frequency,
          "probe_level": probe_level,
          "masker_level": masker_level,
          "target_bel_masking": target_bel_masking
      })

  model_class = model.FullModel()
  model_class.initialize_models(FLAGS.vars_file)
  total_error = 0
  total_points = 0
  baseline_error = 0
  for example in ds.get_all_data():
    # bark_frequency = ds.frequency_to_cb(example["probe_frequency"])
    actual_level = example["probe_level"]
    target_bel_masking = example["target_bel_masking"]
    prediction = model_class.predict(example["masker_frequency"],
                                     example["probe_level"],
                                     example["masker_level"],
                                     example["probe_frequency_bark"])
    error = (target_bel_masking - prediction)**2
    baseline_error += (target_bel_masking - 0)**2
    total_error += error
    total_points += 1
  print("Num predicted: ", total_points)
  print("Baseline Mean squared error: {}".format(baseline_error / total_points))
  print("Mean squared error: {}".format(total_error / total_points))
  if FLAGS.plot_all_curves:
    plot_all_learned_curves(ds,
                            [843.0, 843.0, 843.0, 843.0],
                            [20, 20, 40, 40],
                            [50, 70, 50, 70],
                            model_class,
                            FLAGS.save_dir)
  if FLAGS.plot_ood_curves:
    mask_frequencies = [1370.0]
    probe_levels = [30]
    mask_levels = [80]
    plot_all_learned_curves(ds, mask_frequencies, probe_levels, mask_levels,
                            model_class, FLAGS.save_dir)