简单的优化 [英] Simple optimization

查看:54
本文介绍了简单的优化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不确定这是不是正确的地方。无论如何在学校,我们被教导,当他们试图计算算法的效率时,他们会把重点放在一个叫做FLOP或浮点运算的东西上。

忽略所有整数运算。


我的问题是这个。我正在通过大型风景写一个动物驱散模拟

。我们正在加载来自几个不同的
文件的数据,以模拟动物将要经过的环境。

因此,对于每一只动物,我每一天的每一步都是每一步

必须在地图上找出动物的新位置,然后

检查动物被捕食者杀死的可能性是什么,
然后,如果他们活下来,看看周围是什么类型的食物,并得到一个吃东西的机会
。然后他们正在经历的是什么类型的环境(开放式草原可能会让一些物种相对移动,而其他物种可能会在周围流动并留在树林中)和/>
等等。这些决定中的大多数将通过比较一个值(一个未确定的现在)

随机数生成器的值来确定。那么我应该将值设置在0-100

之间并生成随机整数吗?或者将值设置为0.0到1.0然后

在该范围内生成一个随机的双倍。


科学家并不太担心他们的细节有多精细

可用于查找查找食物的价值或任何事情(1到100将告诉我b
),因此效率是本轮游戏的名称。


欢迎任何建议或想法


感谢您的时间


欢呼


bob

Not sure if this is the correct place or not. Anyhow in school we were
taught that when trying to calculate the efficiency of an algorithm to
focus on something called FLOPs or Floating Point operations and
disregard all integer operations.

My question is this. I am writing a simulation for animal dispersement
through large landscapes. We are loading data from several different
files to simulate the environment the animals will be traveling through.
So for every time step for every day for every year for every animal I
will have to figure out the new location on the map for the animal, then
check to see what the chance is the animal was killed by a predator,
then if they survive that see what type of food is around and get a
chance on getting something to eat. Then what type of environment they
are moving through (Open prairie might have some species move relatively
straight while others might circle around and stay in the woods) and on
and on and on. Most of these decisions will be determined by comparing
a value against a random number from some (undetermined as of now)
random number generator. So should I have the values be between 0-100
and generate a random integer? Or have the values 0.0 to 1.0 and then
generate a random double in that range.

The scientist are not too worried about how fine a detail they have
available for stetting the value of find food or what ever(1 to 100 will
work I am told), so efficiency is the name of the game for this round.

Any suggestions or ideas welcome

thanks for your time

cheers

bob

推荐答案

Bob Cummings写道:
Bob Cummings wrote:
不确定这是不是正确的地方或不。无论如何,在学校我们被教导说,当试图计算算法的效率时,要专注于一些叫做FLOP或浮点运算的东西,而忽略所有的整数运算。


这是一种奇怪的方式来看待它...如果算法根本不使用

浮点运算怎么办?这是否意味着你应该认为它会立即完成?

我的问题是这个。我正在通过大型风景写一个动物驱散模拟。我们正在从几个不同的文件中加载数据,以模拟动物将要经过的环境。
因此,对于每一只每一天的每一天的每一个步骤,我都需要确定在动物地图上的新位置,然后检查动物被捕食者杀死的机会是什么,
然后如果他们活下来,看看周围有什么类型的食物,并得到一个有机会吃东西。然后他们正在经历的是什么类型的环境(开放的草原可能会让一些物种相对直接移动,而其他物种可能会四处转动并留在树林中)以及
等等。这些决定中的大部分将通过比较某个值(当前未确定)随机数生成器的随机数来确定。那么我应该将值设置在0-100之间并生成一个随机整数吗?或者将值设置为0.0到1.0然后
在该范围内生成一个随机的双倍。

科学家并不太担心他们有多么精细的细节可用来进行寻找食物的价值或任何事情(1到100将告诉我工作),所以效率是本轮游戏的名称。
Not sure if this is the correct place or not. Anyhow in school we were
taught that when trying to calculate the efficiency of an algorithm to
focus on something called FLOPs or Floating Point operations and
disregard all integer operations.
That''s a strange way to look at it... What if an algorithm doesn''t use
floating point operations at all? Does that mean that you should
consider it to complete instantaneously?
My question is this. I am writing a simulation for animal dispersement
through large landscapes. We are loading data from several different
files to simulate the environment the animals will be traveling through.
So for every time step for every day for every year for every animal I
will have to figure out the new location on the map for the animal, then
check to see what the chance is the animal was killed by a predator,
then if they survive that see what type of food is around and get a
chance on getting something to eat. Then what type of environment they
are moving through (Open prairie might have some species move relatively
straight while others might circle around and stay in the woods) and on
and on and on. Most of these decisions will be determined by comparing
a value against a random number from some (undetermined as of now)
random number generator. So should I have the values be between 0-100
and generate a random integer? Or have the values 0.0 to 1.0 and then
generate a random double in that range.

The scientist are not too worried about how fine a detail they have
available for stetting the value of find food or what ever(1 to 100 will
work I am told), so efficiency is the name of the game for this round.




如果你使用整数或浮点并不是那么重要。

你应该更关心算法的效率。


随机框架中的生成器生成一个浮点随机

数,所以要得到一个整数随机数,还需要一些更多的b $ b b计算。另一方面,整数计算比浮点计算稍微快一点,所以一旦你在某些计算中使用随机数,它可以证明更快




If you use integers or floating points doesn''t really matter that much.
You should be more concerned about how efficient the algorithm is.

The random generator in the framework generates a floating point random
number, so to get an integer random number there are some more
calculations needed. On the other hand, integer calcualtions are
slightly faster than floating point calculations, so it may prove faster
once you use the random number in some calculations.


我见过的每个随机数生成器都使用浮点数,如果你愿意,你可以转换成一个整数,但是可能没有' '$

多点。


如果我是你,我就不会注意浮点数而不是

整数。我会注意那个时间步骤:我有什么需要每个动物为每个蜱计算
时钟,并且有任何方式




1)设计我的数据结构,以便计算非常简单。

(例如,如果你想知道这只动物是否被一只b $ b b捕食者吃掉,如果你将动物与每只捕食动物进行比较

整个' ;每次都会很慢。如果你可以设计你的

数据,这样就可以快速确定附近有哪些掠食者

,你可以加速大大的事情。)


2)设计我的数据结构,以便可以跳过某些动物的步骤。这可能是不可能的,但基本的想法是

如果一只动物足够在一个地方吃饭,比如七天,并且

没有掠食者在附近,然后设计一些方法来跳过处理

这种动物七天。类似的东西。


最重要的是,真正的效率来自于查看

问题和大型解决方案,并看到你可以在哪里玩

欺骗以避免进行计算。一旦你处于某种情况下,你需要进行计算,你经常会超过这一点

,你可以在这里获得显着的效率提升。 />

也就是说,总有例外。你的程序可能是

之一。然而,最好的起点是大规模问题

和用于解决它的算法/数据结构。一旦你确信

,你就不可能设计你的程序以避免工作......只有这样才能担心小规模的效率,比如是否使用整数或

浮动。

Every random number generator I''ve ever seen uses floating point, which
you can convert to an integer if you want to, but there probably isn''t
much point.

If I were you I wouldn''t pay any attention to floating point versus
integer. I would pay attention to that time step: what do I have to
calculate for each animal for each "tick" of the clock, and is there
any way to:

1) Design my data structures so that teh calculations are really easy.
(For example, if you want to know whether the animal was eaten by a
predator, if you compare the animal against every predator animal on
the whole "board" every time, it will be slow. If you can design your
data so that there is a fast way to determine which predators are
nearby, you can speed things up substantially.)

2) Design my data structures so that it''s possible to skip steps for
certain animals. This may not be possible, but the basic idea is that
if an animal has enough to eat in a location for, say, seven days, and
there are no predators nearby, then design some way to skip processing
that animal for seven days. Something like that.

The bottom line is that real efficiencies come from looking at the
problem and your solution in the large, and seeing where you can play
tricks to avoid doing calculations at all. Once you''re in a situation
where you have to do the calculations, you''re often past the point
where you can make significant efficiency gains.

That said, there are always exceptions. Your program may be one of
them. However, the best place to start is alway the large-scale problem
and algorithm / data structures used to solve it. Once you''re convinced
that you can''t possibly design your program to avoid work... only then
worry about small-scale efficiencies like whether to use integers or
floats.


布鲁斯伍德写道:
每个随机数生成器我''曾经见过使用浮点数,如果你愿意,你可以转换为整数,但可能没有多大意义。

如果我是你我不会注意浮点数与
整数。我会注意那个时间步骤:我需要为每个动物计算每个蜱的数量。时钟,有没有
任何方式:


好​​的这是一份副业,我已经两年没有上学了。

我的大多数官方工作不是这样的。因此,在我的设计阶段,我想要确定要存储什么类型的数据

,这似乎可以产生巨大的差异。我想我错了,

不是第一个或最后一个。

1)设计我的数据结构,以便计算非常简单。
(例如,如果你想知道动物是否被捕食者吃掉,如果你每次将动物与整个板上的每只食肉动物进行比较,它就会很慢。如果你能设计的话你的
数据,以便有一个快速的方法来确定附近的掠食者,你可以大大加快速度。)


我想我们已经在那里了顺便说一句,我们使用

形状文件加载数据。我将只让动物比较他在

一张地图上的确切位置,然后从该位置的其他地图中获取值

进行比较。这样我就不会遍布整个景观。

2)设计我的数据结构,以便可以跳过某些动物的步骤。这可能是不可能的,但基本的想法是,如果动物有足够的食物在一个地方吃,比如七天,并且附近没有掠食者,那么设计一些方法来跳过加工那种动物七天。这样的事情。


我的动物确实有不同的行为模式来模拟其中的一些。

例如,如果他错过了被捕食者钉死的话,他会进入

逃离模式一段时间。没有喂食,没有寻找伴侣,没有

现在只能打败脚离开这里。如果他有足够的能量

储备,那么我们就不会寻找食物了。我想这就是你在谈论的b $ b?我们传递的参数之一将是动物看到的范围。在他周围做出一些决定,但是我认为如果只是一点点,我将不得不每次都要移动。

底线就是那个真实的效率来自于查看
问题和大型解决方案,并看到你可以在哪里玩耍,以避免进行计算。一旦你处于需要进行计算的情况中,你经常会超越这一点,在那里你可以显着提高效率。


好​​点我会把那些资助

项目的科学家带上来,看看我有没有时间能做到这一点让他们做

的决定。我已经和他们一起讨论了这个问题,而且他们不会过分担心效率问题。相反,他们想尝试和b
在模仿现实生活和收集数据之间找到平衡,以便在将来做出决定。
浮点数。


感谢您的建议。请小心这样的帮助,我会回来寻求更多的帮助。
Every random number generator I''ve ever seen uses floating point, which
you can convert to an integer if you want to, but there probably isn''t
much point.

If I were you I wouldn''t pay any attention to floating point versus
integer. I would pay attention to that time step: what do I have to
calculate for each animal for each "tick" of the clock, and is there
any way to:
OK this is a side job and I have only been out of school for two years.
And most of my "official" work is not like this. So as I am going
through my design phase and trying to decide what type of data to store
this seemed like it could make a huge difference. I guess I was wrong,
not the first or last.

1) Design my data structures so that teh calculations are really easy.
(For example, if you want to know whether the animal was eaten by a
predator, if you compare the animal against every predator animal on
the whole "board" every time, it will be slow. If you can design your
data so that there is a fast way to determine which predators are
nearby, you can speed things up substantially.)
I think we are there already by the way we are loading the data using
shape files. I will only have the animal compare his exact location on
one map then get the values from the other maps at that exact location
for comparison. That way I am not looking all over the entire landscape.

2) Design my data structures so that it''s possible to skip steps for
certain animals. This may not be possible, but the basic idea is that
if an animal has enough to eat in a location for, say, seven days, and
there are no predators nearby, then design some way to skip processing
that animal for seven days. Something like that.
My animal does have different behavior modes to simulate some of that.
For example if he just missed getting nailed by a predator he goes into
flee mode for a certain time. No feeding, no looking for a mate, no
nothing but beat feet to get out of here now. If he has enough energy
reserves then we will not be looking for food. I think this is what you
are talking about? One of the parameters we are passing in will be how
far can the animal "see" around him to make some of those decisions, but
I think he is going to have to move every time step if only a little bit.

The bottom line is that real efficiencies come from looking at the
problem and your solution in the large, and seeing where you can play
tricks to avoid doing calculations at all. Once you''re in a situation
where you have to do the calculations, you''re often past the point
where you can make significant efficiency gains.
Good point I will bring that up the the scientists who are funding the
project and see if there is any time I can do that and let them make the
decision. I have already discussed this issue with them once and they
are not too concerned about efficiency. Rather they want to try and
find a balance between mimicking real life and gathering data in a
simple enough form to make decisions in the future.

That said, there are always exceptions. Your program may be one of
them. However, the best place to start is alway the large-scale problem
and algorithm / data structures used to solve it. Once you''re convinced
that you can''t possibly design your program to avoid work... only then
worry about small-scale efficiencies like whether to use integers or
floats.
Thanks for the advice. And be careful with great help like this I will
be back asking for more help.



这篇关于简单的优化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆