Saturday, September 17, 2011

Build a numerical simulation in medicine and biology. Part Three.

How exactly does this example of a simulation actually work? Looking at the kinetics of plants growth (green dots) one can come to the conclusion that they tend to diffuse. This means that they extend its reach into areas adjacent. Of course there are different ways to use the plant migration vectors (birds, wind etc.), in order to deal with distant sites. In my simulation, we can set three factors responsible for plant growth.

1st Plant growth, is responsible for the speed with which the plant increases the intensity of a given area, which has already been occupied by it. 
2nd Diffusion Plant, specifies the rate at which the plant occupies the areas adjacent to already occupied. 
3rd Generating plants every x cycles, is associated with the random creation of plants on the board, this is reflected in the use of vectors carrying the seeds over long distances. 




The role of herbivores meet the so-called "agents", ie objects performing certain functions and having the ability to communicate with each other. Agents move on the board in the manner defined by several variables. Pheromone, which is the key to communication, diffuse, and at the same time is removed (extinction). Each agent has a finite pool of receptors to saturate, if the maximum concentration is reached, it will not be able to determine the local gradient and make a decision about choosing the direction of movement, which is consistent with the mechanisms reported in nature. It should be noted that the saturation kinetics and regulation of neural receptors, are essential for adequate response to a stimulus.


1st Pheromone diffusion coefficient : Corresponds to the rate of diffusion of signal substances in the domain of spatial simulation. The higher the value, the faster diffuses a pheromone, allowing agents to react in a range of non-zero concentration. The high diffusion coefficient causes a more rapid achievement of equilibrium, thus reducing the time shift between finding a food source, and the following of it. 
2nd Persistence of pheromone associated with disappearance of the old sources and cleaning the spatial domain of residual pheromone. Too high durability makes the receptors fully saturated and the agent will not be able to make decisions about the direction of movement. Too low durability will cause the disappearance of the signal before agent reaches its source. 



It is worth mentioning that the simulation takes place on the board, whose boundaries satisfy the condition of zero flow (no flux boundary). Nothing gets across the border simulation. 
Agents have a random component of mobility (random movement of agents), which is particularly the more important for the movement, the lower the local gradient of pheromone. This means that if no food source, the objects are moving randomly, but also if there is too much of food around.




The simulation consists of a spatial domain X of X field, defined by the variable "simulation size" You can also choose a number of agents, changing the "agents number" selector. Selecting a large value, the action slows down, because this increases a computational cost. Cose is roughly proportional to the sum of second power of array dimension and number of agents.

 At any moment, pressing pause, freezes  the simulation for a moment and allows the user to track the pheromone concentrations, without losing the view of the board with food and agents behavior. 
Feel free to use the simulation in you own purposes.

Friday, September 16, 2011

Build a numerical simulation in medicine and biology. Part Two.

Boids simulation, feeding time ;-)
                 The subject of a topic is a hybrid simulation, consisting of objects moving in the environment, based on pheromone secreted by themselves to find the source of food. Area where the object take part is a virtual grid and the spatial coordinates of objects are projected onto the cell array. An array is used to operate on concentrations and gradients of pheromone and storing data for each iteration cycle. I called the simulation “hybrid”, because it combines computing the data with an array and projection on the graphics window in which the agents actually live. 
                Agents systems are characterized by large amounts, typically primitive objects, which themselves would not be able to perform its complex functions. Only the communication in the group provides a higher degree of complexity. An example of this method of interaction is the anthill and termitary. Chemical communication between insects is composed of many substances and its combinations, according to events essential in survival. Chemicals marked routes, obstacles, sources of food, and many others. Agents developed a variable half time of chemical signals, thus, decompose and diffusion in a specific rate, optimizing the performance of the tasks for which they are intended. 
                Not renewing chemical paths disappear after some time, as is the case with the determination of dangerous places and food sources. This allows dynamic conversions, corresponding to the current and past situations. Stimulus intensity is associated in nature with receptor saturation, which takes a finite number of states and is of characteristic kinetics. It is a model of how to determine the shorter path through the strengthening of the chemical. 
                Calculations of this type using computer require discretization, thus determining the spatial resolution. The higher it is, the higher the computational cost, growing with the second power in two-dimensional model in the case. 
Construction of  algorithms associated with the project, should base on software engineering methods. I am so far remained loyal to procedural programming, because I am not obliged to modularity so important when developing complex applications. Methods implemented should include array calculations: diffusion, gradient determination, which can be implemented using proper convolution kernels or directly. In addition, the important functions are the projection of each agent position coordinates on the arrays, allowing agents to access chemical data of area they occupy. The functions dealing with user interface and drawing graphics belong to other, essential elements. 
                The behavior of individual agents should be created according to accepted rules, and  constants chosen experimentally, or drawing from nature. In this case, the key is the movement of objects, which should be the sum of random motion and directional-dependent gradient of pheromone and receptor saturation. This allows for a spontaneous grouping of objects and interaction. As soon as you lose the target, group begins to move randomly. The first agent, who sees the next target, releases the pheromone, focusing rest of the group. The right extinction constant of pheromone diffusion, allows for modeling the behavior of many real world species.  The next steps of this type of simulation may be to add a finite supply of energy for individuals, and reproduction, which would allow the observation of population dynamics in conditions of limited food supply. However, these requires a change to more efficient programming language. An example might be C + +. 

Build a numerical simulation in medicine and biology. Part One.

my simple boids simulation
                Every problem can be described using the language of mathematics, but the question at what level we wish to remain. The ideal is to take account of fundamental rights, which show all the rest. Then we create a very realistic simulation, where everything occurs spontaneously. The downside is the cost of computing and often quite complicated boundary conditions. Because the lower level we choose, the more calculations we have to do (although often these calculations are simpler). 
               An example of a simple idea is to calculate the propagation of inviscid fluid through network of connected vessels. These vessels form a circulatory system of man for example.  The problem is identical with the calculation of resistance of replacement network of interconnected resistors, or current flow in electrical networks. You can use the method of nodal potentials, delta-Wye solution, rely on Kirchhoff's law. This requires usage of equations systems and solve it one of the available methods, for example, by Gauss. Otherwise, you can try to apply the transform of the delta-wye (delta - y), to transcribe entire network of resistors (communicating vessels), as a series-parallel arrangement. Then simply use the already familiar with the primary method used to calculate. Beautiful ideas, but still quite complicated and difficult to implement. The algorithms necessary for the calculations are quite complicated and write, debug them, may take a very long time. 
               But if you think you can come up with a simpler idea, offering a solution less accurate, the convergence (to determine the final solution), which often have to wait a bit. Method based on the idea at once banal and beautiful. Well, for every  network node the same amount of fluid comes in, than comes out. Whether we talk about electric current, or a liquid. As the resistance of connections, we cannot modify, we affect only the pressure in each step. In each step of the simulation, modifying the pressure in the network nodes to balance the quantities of liquid entering and leaving was zero - which is an equivalent of lack of accumulation (non compressibility condition). 
               But everything depends on the use of simulation. Programs for electronics design, based on complicated mathematical apparatus, can’t wait to determine the numerical solution of the assumed error. This would be impossible and unprofessional. In this case, we put more work and create a reliable and fast algorithm, giving instant and accurate solution. 
               Another problem is choosing the method of calculation. Do you peel the analytical methods or numerical? If the boundary conditions for known already established analytical solution exists, you can try to use it. For example, the heat loss by a man at rest. Someone measured it, set the coefficients for each of the methods of heat loss and posted a solution. Does it make sense to model the skin perfusion, each of the ways of heat loss, including the account convection in the atmosphere? You can, but it borders on insanity. It requires a lot of knowledge (fluid mechanics, etc.), computational power, and the same number can be achieved using a simple formula. 

               In practice, it often turns out that the solution of the model differs significantly from the observations (the worse for observation!). In fact, you have to deal with it. Each simulation is simplification of the real world. If the results are significantly different from each other, it probably means that one of the important factors wasn’t included. This is important in nonlinear problems. An example here would be forecasting the weather. Models can be perfect, but a small measurement error, or not quite dense network of meteorological stations, makes the forecast misses the truth after a few days. 
               No less important is the presentation of data listed. How many dimensions we are able to fit on the surface of 2D? It appears that up to 2, You can, however do much more. Coding of color, shape characters and symbols allow you to place a few times more data. The problem is readability. 
               Graphics and animation much more speaks to the audience's imagination, than the pillars of graphs, but charts and bars much more than tables of figures or just plain numbers. Although the animation is often unavailable to the needs of education, such as most bars charts. Always avoid numerical data in raw form. Spare no graphics and charts. 
               Choosing a programming language, unfortunately, is often a choice of lesser evil, between 'how fast can write "and" how fast will work".  At least in the case of numerical simulations where speed od calculations is critical. Please be aware of computing power it’s available for you to use. Most problems can be resolved quickly enough even using relatively slow FLASH. The advantage is its portability between platforms and availability for your browser. Similarly, the situation is with Java, except that Java  is much faster. Jobs once said that "if something uses flash, it is certainly possible to fry an egg on it" and had a little wrong. Since then, one will not find a flash player installed on devices from Apple. The speed of calculation provides a C + +, especially if you use accelerated computing on the GPU nVidia CUDA. Alone with this technology still did not use, but I know that not every calculation can be accelerated. Acceleration is greatest when large amounts of simple calculations, the best on grids, which can easily be divided into individual units spreadsheets. With this, amount of transfers between RAM  and GPU should be as small as possible. If we care about time, good, if a programming language provides us with ease of presentation of the data in graphical form, or interactive. Operation using the command line, not the most user-friendly.  
               Everything should be considered before we start the project. In the middle it is difficult to change the design of the project, and if decide so, we lose a lot of valuable time and workhours. 
Related Posts Plugin for WordPress, Blogger...