DDSパラメータを求める

  • タグ:
  • タグはありません
Base = 50000000
Goal = 1789772.5

div = (Base / Goal).round

best_add = 0
best_max = 0
best_gosa = Base.to_f
for add in 1..100
	gosa_min = Base.to_f

	hosei = -add

	loop{
		max = div * add + hosei

		hz = 0
		count = 0
		amari = 0

		for i in 0..Base
			if count > max
				count -= max
				amari += count
				hz += 1
			else
				count += add
			end
		end

		hzo = hz + count / max.to_f
		h = hzo - Goal

		if h.abs < gosa_min
			print "加算値 ", add, "  しきい値 ", max, "  補正 ", hosei, "\n"
			gosa_min = h.abs
			if gosa_min < best_gosa
				best_add = add
				best_max = max
				best_gosa = gosa_min
				print "更新 誤差 ", best_gosa, "\n"
			end
		else
			break
		end

		if h > 0.0
			hosei += 1
		else
			hosei -= 1
		end
	}
end

print "加算値 ", best_add, "  しきい値 ", best_max, "  誤差 ", best_gosa, "\n"