text:
Programming Mac OS X with Cocoa for Beginners/Objective C, the language and its advantages

Previous Page: First Cocoa program - Hello World | Next Page: Some Cocoa essential principles

In the last chapter, we were introduced to Objective-C, and used it to write the "Hello World" code in an object-oriented fashion that worked with Cocoa. Now we will learn more about Objective-C as a language, and why it has certain advantages. This isn't meant as a complete guide to Objective-C, more of an overview. There is another wikibook that goes into far more detail. The original goal of Objective-C was to create a language that is efficient and productive, while avoiding being overburdened with too many features that are often only of theoretical benefit. As a strict superset of C, this does mean that some of C's drawbacks remain in Objective-C, but on the other hand it makes it much faster to learn. Becoming an expert in C++, with its myriad of features, can take years. It's probably fair to say that this learning curve for C++ means that much C++ code is not written as perfectly as it could be. Mastering Objective-C, by contrast, is quite easy, so code quality can be higher at an earlier stage. That said, Objective-C doesn't provide other features which can reduce bugs, such as const (read only) objects, and so forth. (In Cocoa, read-only objects are established by design, for example NSString is read only, whereas NSMutableString is read/write).

We have already seen much of the basic Objective-C syntax. Object methods are accessed using the square bracket notation, and parameters are passed using colons and parameter names. Methods are just like functions in C, only the syntax of how they are called differs. This different syntax is required because we need to specify WHAT object we are referring to, and WHICH method we'd like it to carry out. The square brackets link these two pieces of information together. Other than that they are just like functions — they can return an optional value, and take any number of parameters.

The body of a method is also just like a function. We start with the name of the method and its return type, then enclose the method's code in curly braces, just as in C. Within the code, we have seen that we can refer to the object itself using 'self'. This saves us from having to find out our own address, the compiler will handle all of that. Most objects we'll encounter are subclasses of other, already existing objects. In Cocoa, there is a generic base object class called NSObject, which contains a lot of useful functionality that most classes will wish to inherit. So in general we can be sure that every object has an ancestor object. We can refer to the most immediate ancestor object (called the superclass of the object) within any method body using the shorthand 'super'. This is like self, but refers to the immediate ancestor instead. Super is most often used when you need to override a method in your current class with a method in the superclass. Self is used much more often than super, but occasionally we'll need to use super.

We saw how IB helped us out last chapter by creating the skeletons for our custom view class for us. Every class consists of two parts — the interface and the implementation. Usually these are placed in separate files, the .h and the .m respectively. The idea of this two-part design is both to make managing your code easier, and to encourage you to hide implementation details. Remember, objects should be usable from external code without the internal details of how they work being exposed. If we endeavour to hide all of the internal parts from the outside world, we will encounter fewer bugs, because we have eliminated dependencies on those details. Thus the interface (.h) file is used to tell the world about your object's methods, and the implementation file contains the code that makes it work, but should be of no interest to the outside world. If you use external libraries, very often you'll simply not have access to the .m files — only the .h files are available. This is true of Cocoa itself; you will do well to follow the same model.

Within the curly braces you can add data members (or just members) to the class. Data members are like variables that are owned by concrete instances of the object. Every separate instance has its own copy of the data members, and they can have independent values. Data members are used to store the actual values of the properties of the object.

Methods are just like function prototypes. They go after the data member section, but before the '@end' statement. As in C++, they are required, but unlike C++, only those that are unique to the class are required — overrides of superclass methods don't need to be written out again. This helps the user of the object focus on what is unique and interesting about this object, as opposed to its superclasses. In other words the implementation file is a strict delta or difference file from the superclass.

Let's add some data members and methods, as an example.

We have added three data members, an integer called, an integer called  , and an NSString called. The leading underscores used here are just part of the name, they have no special meaning, but they can be quite handy. Within code you write to implement an object's methods, you can refer to the object's data members simply by naming them, as if they were variables local to that function. By using the underscore, you can tell at a glance that they are data members, and not local variables. Any similar convention you might care to use is a good idea — getting confused between what is local, global or an object's data member is a recipe for bugs.

We also added four methods,,  ,   and. Remember, the colons are part of the method's name. Method names should follow this convention in Cocoa. Whenever you want to set a property, create a method called, and whenever you want to ask for that property, create a method whose name is the property. Some programmers might be tempted to call such a method  — don't do this! In Cocoa, this naming scheme is more than just a convention, it is used later to allow us to automatically read and write properties in all sorts of simple and elegant ways that are awkward or impossible in other programming languages.

Since  is just an integer, couldn't we just refer to it from elsewhere without having to go through all the overhead of calling a method? Yes we could, but we'd be breaking the rule about hiding the implementation. Suppose at a later stage you decided that this object should calculate the age by counting tree rings, instead of simply storing it. If external code was peeking at the integer, it would stop working when we changed the code within the age method so it counted tree rings. So never, never peek at data members from outside of an object. Even within the object, we should usually call our own methods to read our data member's values, since again, if later we change the way it works, we can minimise the number of places that need to be changed by making sure that there is only one main place that deals with that value.

Note how we declare a method's parameter types. We put the type in parentheses following the colon. We can also, as here, nominate a variable name for the parameter, though as in C this is optional. However, since the parameter name is built into the method, leaving it out doesn't leave us with an undocumented mystery, as it does in C. In other words:

gives us all we need to know about what the method does, leaving no mystery. We have the names of the parameters (text and size) and their types ( and  ). For contrast, in C you might have had something like:

What is the second parameter? Unless the programmer used a more descriptive name or added a comment to tell us, we can't tell.

The return types of the method are also indicated using the same bracket notation. In addition, the leading '-' is important — this tells us that this is an instance method, one that pertains to a particular instance of an object. If we wanted to declare a class method, we would use a '+' symbol instead. This use of + and - allows us to tell at a glance which methods are which in the interface file. C++ by contrast uses the 'static' keyword for class methods.

Finally, notice that the interface imports the  file at the top. is just like, except that it automatically includes the file only one time, so you don't need to use any #define tricks to ensure it. Here we import Cocoa so that we get the interface for, of which this is a subclass. At the very least, a class interface must somehow make details of its superclass known, though where you are subclassing a Cocoa object, using #import is best.

Implementation
The implementation of an object is placed in the .m file, and is declared like this:

The implementation of an object is everything between  and. The methods are coded just as a C function. Here we have our unique methods,  and so on, and also a couple of methods that we inherited from our superclass,   and   These last two don't appear in our interface file, as they are not a unique feature of this class. To override them, we simply redefine the methods in the implementation.

The  and   methods should be fairly obvious — the values are simply assigned to the data member , or return its value. Many methods that simply read and write properties of an Objective-C object are like this — short and simple. It can get a bit tedious to write these all out if you have many properties, but don't be tempted to avoid this, because hiding the implementation is much more important in the long run.

The  method is a little more complex, since we need to retain and release objects. We'll be covering this in detail in the next chapter, so don't worry about it for now. However, this is required most times that you are using objects as properties of other objects, which will happen a lot. Simple values such as the int  can just use simple assignments. The last line,  is an example of calling one of your own methods. Here, we use the method  which is inherited from. This signals to Cocoa that the view content has changed and should be redrawn. Cocoa makes a note of that and will cause our  method to get called in due course, so anyone who makes use of the   method of our view will see those new settings appear immediately.

The  method also sets these various data members to some default values, so that the object will work even if nobody ever comes along and sets the text, its size, etc. Every object has an   method whose purpose is to establish the object's default properties so that it will function properly right out of the box. Sometimes, objects will need parameters sent to the  method, so a different version of an   method is needed, as the way   was coded. Note that the  method's first job is to call the superclass's   method. This happens all the way back up the chain of ancestor classes until everyone has initialized what it knows about. So there are two main rules to follow when writing your  method:

 * call your super's  method
 * initialize only what you know about (your own data members only)

The  method must return 'self' as its result, provided that the super's initialization succeeded. If not, it will return nil and so should you. If your own initialization fails, but your super's succeeded, you should return nil also. This indicates to the caller that something went wrong while making your object. More about this later.

Some Objective-C advantages
Like C++ and other object-oriented languages, Objective-C supports polymorphism. This means two different things. In the first place, it means that you can have different methods that differ only according to their parameter types, and the correct one will be called according to what you're passing. This is static polymorphism, so in C++:

are two distinct methods. The right one is called depending on whether you pass an int or a float. While handy, this can get confusing, especially when automatic type conversion is taking place, as it frequently does between simple scalar values. Objective-C doesn't support this type of potentially ambiguous polymorphism. Instead, because parameters are an inherent part of a method's name, you can make it much clearer, e.g:

There is no ambiguity, since you have to name which one you mean explicitly. This might reduce the potential for bugs for some people, though C++ programmers might grumble.

The second kind of polymorphism is dynamic polymorphism. We have already seen this in action in our simple program. When Cocoa calls the view's  method, it actually doesn't have a clue that the object in question is a , and not a plain vanilla NSView. It calls our object as if it were an NSView. The method call resolves to our custom object however, and so our code gets called, allowing it to do its thing. All object-oriented languages need to support this kind of polymorphism, so the fact that Objective-C does too is no surprise.

What is different is that Objective-C resolves the method at runtime. This is in contrast to languages such as C++ that resolve everything at compile time, building a set of fixed tables that allow this apparent magic to occur. For the typical case, this runtime binding makes no difference. However, there are other cases where the runtime binding makes a huge difference, and this adds a degree of power to Objective-C that is absent from C++ and others. It safely allows us to use anonymous objects, and even null objects. It allows us to create a delayed method call called an invocation that can be used later, and it permits things like Undo to be implemented much more easily. It greatly helps us create a graphical user interface for our code, because commands, actions and so on of various window controls can be made extremely general. It also permits something called "Key-value observing" and "key paths" which are incredibly powerful — more on these later.

Let's suppose we have an object that must respond to a click on a button in a window. Really, the button shouldn't need to care which sort of object it is controlling, only that when it is clicked, it should do something. Let's suppose a method exists called, and the button knows that it should call this on an object called 'target' when clicked. In a traditional language, the target object's type must be known to the button, so that it can determine if a method called  really exists. Once that type is indicated to the button, it can only ever deal with objects of that type, or their subclasses. However, in Objective-C, we could hook up totally unrelated objects to the button, and as long as they implemented, they would respond to the button. This is a great improvement in flexibility. Many GUI elements such as buttons and menus use this type of target/action approach.

An 'anonymous' object has a type of 'id'. Anywhere you see 'id' used as an object type, an anonymous object reference is created. 'id' can stand in for any type of object whatsoever.

In Objective-C, the value nil has a type of id. This means that nil is an object! (NULL, meaning nothing, is still available) In other languages, especially C and C++, we must be careful not to use an object reference of nil, meaning we have to litter our code with lots of checks, like:

In Objective-C, we don't need to bother. Calling a  object's methods is harmless, because of the runtime binding of the method call. Of course the action won't do anything, but it won't crash.

Another example. Let's suppose we want to invoke a periodic action on one of our objects. Cocoa has a handy class for setting up periodic actions,. One day we might want our 'GCWidget' class to have its 'dwim' method called once a minute, another time we have an unrelated HPSprocket class that needs its 'fubar' method called every 5 seconds. In a traditional language, both of these classes would have to inherit from a common class known to NSTimer, and in addition the periodic method would have to have the exact same name. But because of the runtime binding and anonymous objects, NSTimer simply needs to be told the method name to call, and call it on an object type of 'id'. If the object implements the method, it does its thing. If not, nothing bad happens.

Objective-C implements the runtime binding using a mechanism called a selector. This helps make the process a lot more efficient — as you might imagine if a method lookup really had to go through and compare the actual names of the methods letter by letter it would be very slow. Instead, at compile time Objective-C converts every method name into a simple unique number which is much faster to lookup. There is still a cost compared to C++'s approach, but the benefits are worth it. In practice, a method call in Objective-C is probably only about 2 or 3 times slower than a C++ method call.

We can obtain the selector for a method using the '@selector( ... )' function. Sometimes we need to do this when we are setting up targets and actions, as in our timer example above.

Previous Page: First Cocoa program - Hello World | Next Page: Some Cocoa essential principles


text:
Korean/Lesson II4

 * Bus 버스 (beoseu)
 * Taxi 택시 (taek shi)
 * Train 기차 (gi cha)[This is just train in general. KTX is the new bullet train in Korea and they will know what you are talking about if you ask for the location of KTX, but remember that KTX is more expensive. You can also ride the 새마을 for about $10 less or the 무궁화 for half the cost of KTX, but neither are as fast nor as well kept.]
 * Subway 지하철 (ji ha cheol)
 * Car 차 (Cha)[also the word for tea]
 * Station 역 (yeok)[as in subway/train station. For example, Seoul station is 서울역]
 * Subway line or route 선 (seon). [For example, if you took the yellow subway route, or the 분당선, there is a stop at 야탑 where there is an awesome public park and bungee jumping.]

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/

title: Korean/Lesson II4


text:
User:Tyciol

Hi! I've joined Wikibooks for the same reason I joined Wikipedia! I assume the two are connected, and they're both great resources for information, I think in the far future, much of information may be handled like this.

I want to learn as much as I can by reading the articles, and making responsible changes where I see them. Simple errors are at my mercy! Things I disagree with are for my discussion with the author ;)

Wikiversity looks cool too! I hope I can get a degree that way! If not... well then I'll pay for a normal school or something :p Looking into the cutting edge science so I can question the scientists about what programs are most respected.

--Tyciol 09:59, 30 January 2006 (UTC)

title: User:Tyciol


text:
Georgia Water/Policy/Conservation-Efficiency-Reuse

Timeline

 * 2002 (July) - Georgia DNR created the Water Conservation Program "to promote the efficient use of Georgia’s water resources and implement a statewide water conservation plan".*
 * 2003 (Oct) - Georgia DNR released first draft of a statewide water conservation plan and requested online forum public comments.
 * 2004 (May) - Georgia DNR released the final report, *Water Conservation Plan Guidelines,

 * 2005 (Oct) - Georgia Environmental Protection Division appointed members of the Water Conservation Technical Advisory Committee to recommend policies for inclusion in the Statewide Water Plan.

See also: Best Practices in Water Conservation


text:
Programming Mac OS X with Cocoa for Beginners/Some Cocoa essential principles

Previous Page: Objective C, the language and its advantages | Next Page: Building a GUI

We have already seen the basics of Cocoa in action. Last chapter, we talked about inheriting from NSObject, and how we must make sure that we call an object's chain of init methods. Here, we'll go into more detail about this, as it's important. Then, we'll talk about memory management.

Creation
Initialising an object properly is your responsibility. Unlike C++, there is no automatic constructor method, nor an automatic destructor method. However, we can easily do without these as long as we are aware of a few simple rules. Following the rules is necessary for success in Cocoa.

When we instantiate an object:

id  myObject = [NSString alloc];

All we get back is a blob of uninitialised memory. If we were to use this object now, we'd be very unlikely to get the results we wanted. It could even crash. We MUST call the initialiser method:

id  myObject = [[NSString alloc] init];

Then we'll be OK. You'll see this alloc/init combination all the time. So why doesn't alloc simply call init as part of its internals and be done with it? Wouldn't that save us the time and reduce the chance of forgetting? Yes, except for one problem. Sometimes we need a different version of init, that requires a parameter. Since alloc can't know which one we'd like, it leaves the call to us.

Every object has a version of init that acts as the 'master' init - the one we must call when we make that object. Things are arranged so that any other variations of init call it, so everything works properly. The master init method is called the designated initialiser. In most cases this will be the vanilla 'init' method, so using any of the other variants will call init internally. Where this isn't the case, the documentation should indicate the designated initialiser.

'init' is just an ordinary method call, it has no special status like a C++ constructor. Thus it's your responsibility to write the code in init correctly, making sure you call your super's designated initialiser (or any of its initialiser methods that eventually call through the designated initialiser) first. Once you've done that, you should initialise your own part of the object.

Initialisation is permitted to fail. Your object might want to allocate a large block of memory for example. If there is no memory available, you should cleanup anything you've allocated already, then return nil from your init method. Since nil objects can be called safely, it means that running out of memory (for example) will not crash the program.

Destruction
When an object is no longer required, its 'dealloc' method will be called. If you allocated anything as part of your initialisation, or operation of your object, you need to override this method and deallocate it. Once done, you should call the super's dealloc method. You will be frequently overriding dealloc, so become familiar with doing it. However, dealloc is rarely called directly. Instead, it is called indirectly when an object is released.

Retain and Release
Every object that inherits from NSObject implements retain and release. This is a simple memory management technique that relies on reference counting. An object keeps track of how many references there are to it within the program. When there are no more references, the count is zero and it is deallocated. In Cocoa, the reference count is often referred to as the retain count. It's the same thing.

The retain method increments the count, and the release method decrements it. When the count reaches zero, dealloc is called automatically.

When an object is first created, its retain count is set to 1. Thus:

id myObject = [[NSString alloc] init];

'myObject' has a retain count of 1, because there is only one reference to it.

If we then do:

[myObject release];

It will be immediately deallocated, because the count is decremented from 1 to 0, and dealloc gets called. By calling release, we are telling Cocoa we are no longer interested in this object here, and will not refer to it further.

Some people find retain and release confusing, but the rules are really quite simple. If you create an object, you are responsible for releasing it. If you create a new reference to an existing object, you are responsible for releasing it. You create an object using either alloc, or copy on another object, so any time you use these, you need to be aware of the retain/release responsibility. It is yours. If you forget to release, things will probably work out, but you have a memory leak, which can cause problems down the track.

Let's look at the second part, creating a second reference. Suppose you have an object which is part of another object. We saw this in our earlier example, where our GCHelloView had an NSString as a data member. When we are passed an NSString from outside, we don't know who made it, who is responsible for it - we only know it's not us! However, by storing it as a data member, we are creating a new reference to that same string, so we must retain it. What about any previous string that we had there? Well, we created a reference to it, so we must release it.

- (void)		setText:(NSString*) text withSize:(int) size {	[text retain]; [_text release]; _text = text; _size = size; [self setNeedsDisplay:YES]; }

So now we can see what's going on here. We retain 'text' because we are creating a new reference to it, our _text data member, and we are releasing the previous value as we are no longer concerned with it. We don't care where the string came from originally or who made it, we are done with it, so we release it. If someone else is still retaining it, it will continue to exist, but if not, it will be deallocated. Now, what if 'text' and '_text' are in fact the same string? This can easily happen. If we release the old one first, it might get deallocated. The following retain will be acting on a stale reference, which is likely to crash (note, unlike the case of accessing nil, accessing a deallocated object is unsafe). Thus by retaining before we release, we avoid that potential snag. "retain before release" is a common and sensible approach.

Note that the retention of objects is efficient, because only a simple count needs to be incremented. If you were required to make a copy of every object, not only would it be much slower, but you'd have the potential for different copies to get out of step with each other, as well as using up much more memory than necessary.

Autorelease
What happens when we make an object, but we want to hand it over to someone else? How can we ensure that it stays valid long enough to be retained by the other object, before we release it? Look at this:

id myObject = [[NSString alloc] init]; return myObject;

Does the receiver know that this object needs to be released? If no-one releases this object, then we have a memory leak. To eliminate the burden of releasing, we want to mark it for release, when the receiver has done with it. Autorelease designates the object to be released later, it says 'retain the object until the next memory pool is drained'. If you are not explicitly draining the pool, then you can be assured it the return value will remain for use in the receiver's immediate scope.

id myObject = [[[NSString alloc] init] autorelease]; return myObject;

This code is OK, since the returned object is valid, but responsibility for ownership has been passed to the pool.

When control returns to the main event loop, the pool can be sure that any objects that have an interest in the object will have retained it by then, and so it releases all of the objects it has. Any that have no references will be deleted, any that do have references will become owned by the objects retaining them. Everything remains neat and tidy.

Most factory methods return autoreleased objects. This is entirely sensible, and if you write a factory method, you should do the same. For example:

NSColor* red = [NSColor redColor];

NSColor's redColor class method return an autoreleased colour object. If you want to keep this object, you should retain it. If you just want to use it for a few lines, then you don't need to do anything - it will get deleted automatically later, but only after you've finished.

In practice, retain, release and autorelease are straightforward. Some people seem to find it confusing but perhaps they think it's more complicated than it is. To keep an object you're given, retain it. Objects you make are already retained. To throw it away and refer to it no more, release it. If you write a factory method, autorelease it. If you are simply making use of an object returned by a factory method for a short while, do nothing.

Object values
What about when a property of your object is another object, and someone else wants to read that property? Should you retain, autorelease, what? No, you should do nothing. You are already retaining it as it's your property. If the caller wants to retain it, that's their business, and autorelease doesn't come into it because it's not a factory method. So simply return the object verbatim. So:

- (NSString*) text {   return _text; }

is absolutely correct.

Note that if the caller did retain it, you are still completely free to release it when you're done with it. What would be an error would be for the caller NOT to retain it if it wanted to use the value for an extended time (being a time longer than the current event). This is not a new rule - if the caller creates a reference to an object, it must retain it. But if all it needs to do is use that object for a short time, within a single function say, it can simply do so and not worry that it will get released by someone else.

Event loops
We have touched on the event loop without explaining what it is. In a Cocoa application, user activities result in events. These might be mouse clicks or drags, typing on the keyboard, choosing a menu item, and so on. Other events can be generated automatically, for example a timer firing periodically, or something coming in over the network. For each event, Cocoa expects there to be an object or group of objects ready to handle that event appropriately. The event loop is where such events are detected and routed off to the appropriate place. Whenever Cocoa is not doing anything else, it is sitting in the event loop waiting for an event to arrive. (In fact, Cocoa doesn't poll for events as suggested, but instead its main thread goes to sleep. When an event arrives, the OS wakes up the thread and event processing resumes. This is much more efficient than polling and allows other applications to run more smoothly).

Each event is handled as an individual thing, then the event loop gets the next event, and so on. If an event causes an update to be required, this is checked at the end of the event and if needed, and window refreshes are carried out.

Previous Page: Objective C, the language and its advantages | Next Page: Building a GUI


text:
Talk:Jet Propulsion/Compressors

Please give me more details of all type of compressor manufactures and there contact email Id's

Manivannan.R ravimanivasu@hotmail.com

title: Talk:Jet Propulsion/Compressors


text:
User talk:205.250.97.251

You (or someone using your IP address, 205.250.97.251) recently erased and replaced everything from the "Magic: The Gathering" module. I have reverted your actions.

Please do not arbitrarily erase or blank parts of Wikibooks. We consider arbitrary deletion as vandalism; if you continue arbitrarily erasing or blanking parts of Wikibooks, you might become blocked from editing Wikibooks.

If you need to test edits to Wikibooks without harming any pages, please use Sandbox. --Kernigh 04:05, 18 January 2006 (UTC)

title: User talk:205.250.97.251


text:
Template:NOTE

Use:

All parameters are optional.
 * note - the text displayed inside the NOTE box.
 * Wikibookian - The name of the Wikibookian that wrote the NOTE. (Can be important to know who to contact in regard with a particular note)

This template adds a note intended for readers that should be valid independent of Wikibooks (for an alternatives see, , or ).

pl:Szablon:NOTE

title: Template:NOTE


text:
Guide to First Year Teaching/Trouble shooting

The Trouble shooting Section is designed to deal with real issues that the new teacher might be experiencing. The new teacher, or mentor teacher, will submit a module detailing the scenario. Then experienced teachers will respond. Please read the sample below.

Trouble With Mandy (Sample)


text:
Guide to First Year Teaching/Trouble shooting/Trouble With Mandy

Situation: I teach 8th language arts and have had a difficult time reaching some of the students, especially in my 5th period. In this class, I have many students who are below grade level. One particular student, Mandy, refuses to write or read anything I give her. "Miss, why do I have to read this anyway?" I try to explain to her that it is required for the 8th grade and that she might finding it interesting if she gave it a chance. She just brushes me off. When I assign writing projects, she would rather take a zero instead. I know that she has potential; she seems very bright. I just don't know how to reach her. --New Teacher (sample)

Response #1: Relevant Reading Materials You have tough situation on your hands. As a teacher of Language Arts myself, I find that students who refuse to read or write usually feel that the stuff we assign them is boring. (Granted after reading it over and over for the last couple of years, I might agree!) One way I work around this is to bring popular trade books or magazines. At the beginning of the year, I give all my students an interest survey, which helps me get ideas about their hobbies and what topics they like. Then, I visit with the librarian to see what materials we might have available. Sometimes, I build my own library of interesting materials by going to yard sales. I hope this helps. --Miss. Carter, Central Middle School, Texas (sample)

Response #2: Success Builds on Success Having worked with at-risk students in my district for the last 5 years, I have discovered that students like Mandy oftentimes refuse to do work because they believe that they are not good in the subject. So, rather than try, they simply don't put forth the effort. This way if they fail, they can chalk it up to not caring. I would begin with small, simple reading passages or assignments. These assignments should have high interest value and incorporate higher thinking skills. If Mandy can complete these smaller assignments in class with success, she might begin to love her fear of failing and begin to see herself as successful. --Mr. Tweedmoore, Western Middle School, Alaska (sample)

 * Note: This is just a sample page. I hope we can agree on the basic formatting. This makes it easier for the new teacher to navigate.


text:
Jini and Network Computing/Moving an RMI application over to Jini

When moving an RMI application over to Jini, the main issue is to stop subclassing UnicastRemoteObject and switch to using Jini Exporters instead.

The RMI registry is replaced with the Jini Lookup Service (referred to with LUS in many cases)). The RMI registry is for local registration and remote lookup.  The Jini Lookup Service can be used from anywhere on the network that the appropriate routing is available.  The Jini Service Lookup Specification provides for the use of multicast lookup which allows for come as you are computing to occur with no specific knowledge of the network.  Where multicast is not supported or routed, unicast lookup can be used with specific IP addresses/host names.


text:
User talk:Jiushigao

Hi Everyone

I just come here.

Jiushigao

title: User talk:Jiushigao


text:
Jini and Network Computing/Specifying a Codebase

The classic specification of an RMI codebase is typically performed using the java.rmi.server.codebase system property on the command line starting the Java Virtual Machine. There are more powerful techniques that allow a single JVM to serve out remote objects with varied codebases. This mechanism is through the codebase annotation service provider interface available through the RMIClassLoaderSPI abstract class.

One can simply subclass this class, providing the appropriate annotations that are appropriate for the classes in the getClassAnnotation(Class) call. A container could allow the user to specify a codebase that is associated with a classpath that it could associate with a specific ClassLoader. Then the implementation of RMIClassLoaderSPI would use the passed Class to find the appropriate ClassLoader that would then designate the codebase annotation that applied.


text:
Jini and Network Computing/java.rmi.server.RMIClassLoaderSPI

RMIClassLoaderSpi is the service provider interface for RMIClassLoader. It provides the ability for expanded control of the codebase annotation and unmarshalling control through the augmentation of the codebase.


text:
Jini and Network Computing/The jini-users mailing list

This mailing list is a popular list for discussing both technical and community topics related to the Jini platform. There are a wide range of questions asked here and many repeating themes that have created a wide range of attempts at documenting as well as improving on the issues associated with Jini and distributed computing in general.


text:
Jini and Network Computing/Consultancies with expertise in Jini and JavaSpaces

There are many visible signs of consulting opportunities for Jini and Javaspaces based SOA applications. One of the biggest items the community deals with is the rather strong silence from many commercial users. They view Jini as a strategic decision that they do not want to publically discuss and/or expose.


text:
Jini and Network Computing/Vendors selling Jini compatible tools or implementations

There a couple of well known Javaspaces implementations that are separate from the Outrigger service in the Sun contributed implementation.  The Blitz Javaspace by Dan Creswell is an Open Source implementation GigaSpaces provides a commercial product that has a wide range of features including a Javaspaces API.


text:
Talk:How To Become A Good Student

This entire book makes absolutely no sense. No offense, but I think this entire book hurts people more than making them want to learn. Perhaps the author is not English-native, however, that is no excuse for the constant mis-use of the English language. Please edit/remove this book as soon as possible. —the preceding unsigned comment is by 67.150.6.135 (talk • contribs) 06:45, 18 January 2006 (UTC)

Excuse me, but your comment is awfully negative and undermines the spirit of this website, not to mention it is just very rude. I personally enjoyed this Wikibook very much and I think it could be very helpful to someone. Yes, it is obvious that English is not the first language of this author. I however, admire the courage it took for this person to write on a subject that is obviously very important to him, even though he is still struggling with the language. Maybe, instead of making negative comments, someone like you could actually help the author out and edit some of this Wikibook, so that it may be more clear and coherent for others readers. It is nay-sayers like you completely undermine the whole point of Wiki, and quite frankly, you make me sick. Good day. —the preceding unsigned comment is by 12.47.73.242 (talk • contribs) 20:58, 18 January 2006 (UTC)

Message from Author
Well, not being harsh, it will take time for the completion of the book. So I'll slowly first put the main idea as to what to write. Then I'll try my best to make the English crystal clear as possible. You are most welcome to help. You can edit the module for now because it needs some attention. Then you can edit pages especially the ones which are provided by development stages mark. Note:- If you are adding a "Personal Note From Author" or adding your preface please assign a signature with timestamp to know who worte what. —the preceding unsigned comment is by Mastermind 007 (talk • contribs) 10:41, 19 January 2006 (UTC)

Regarding: How To Become A Good Student
Actually, the idea for the book is a very intriguing one at best. It is important that students know how to become better students. I wish that you would only provide constructive criticism. I thank the author for starting this. I will be looking for several links to organizations and books that further educate students. I speak from personal experience because at the moment, I am a student. I'm involved with several organizations that deal with leadership, changing paradigms, and other community work. I would be happy to help you in my spare time with all that needs to be done.--Helius 16:46, 21 January 2006 (UTC)

A Work For Some
Hello! Thank you for sending discussions. I'm the one who came up with the idea of this book, so if you have queries please respond to me. I would be delighted if you can help especially in the English grammar of this book. Please try an effort also to make this book with a good look. Hope you understand the motto of this book! Have a good day and enjoy reading this Wikibook. --Mastermind 007 11:35, 22 January 2006 (UTC)

A Reminder
This is an important reminder of ones who are currently reading this book. This book is mostly for students in order to enlighten them for their future. Since it's for students, I've kept the data as brief and easy as I can. So, if you're editing a section or a part of this book, try to keep it small so that it would be easy for you as well as for other students to understand. Hope you enjoy this book!!! --Mastermind 007 11:53, 22 January 2006 (UTC)

A Simple Request
Hello! Everybody. I think I've worked on this book as much as I can and I think it deserves either a "Collaboration Of The Month" or "Book Of The Month" award. Please support this book as much as possible. Have a good time! --Mastermind 007 17:21, 22 January 2006 (UTC)

Failed Editing Attempts
It was my intention to spend this entire editing session fixing grammatical and communicational errors within this book. I quickly realized, however, that it is, as an editor, an extremely difficult book to approach, due, in large part, to the plentiful usage of first person point-of-view, and the constant basis on the author's personal experiences. This circumstance makes it difficult to both refine grammar and to add new advice and/or content beyond the author's own contributions. This is quite a shame given the author's obviously kind-hearted intentions. That is to say, it is unfortunate that such a book as this should suffer because of communicational barriers.

If the author is still interested in producing and developing this book, I would recommend to them that they take a day to revamp the book from a 7 Habits of Highly Effective Adults/Teens/Etc. style, to a more neutral POV manual of advice, so that it may be more easily approached by outside editors. My email address can be found here if the author would like to discuss this with me personally: Wikipedia Email Service --24.175.54.43 06:32, 7 July 2006 (UTC)

Major Revisions/Additions
D. I just wrote in a preface which described the importance and use of this page. I tried to explain the importance of this page as simply and as concisely as possible. If anyone can improve it or add additional information I would invite them to edit it.

I just spent a fair bit of time on each of the chapters (except the last one, which is only a single paragraph at the moment) and I am quite happy with how things turned out. Overall the thing is still simply too difficult to read, but I intend on fixing this soon. Also, despite having covered the very basics, we need to spend time getting some more useful content into each of the chapters. I think the chapter on management is the most important one at the moment.

Chapter 1: Motivation is fine at the moment, but nothing too special. Chapter 2: Concentration on studies has been improved nicely, but once again will need work later. Chapter 3: Behaviour is almost useless at the moment... I really can't see some guy reading that chapter and getting anything out of it. However, I do see potential in it. Chapter 4: Management is where I feel we should focus our energy. Putting things like 'how to keep a good study plan' would be invaluable in this book. Chapter 5: Helping Others And Advising... I seriously think this would be one of the things that should be put at the very end of the book, as the book is about helping yourself, not others. But if this book was fairly developed, then I would welcome it.

Well I'll see what I can do, but I know this could be a very good book if we work on it. --Babij 08:31, 8 July 2006 (UTC)

Agreed. Needs major work before it can be considered complete. Plus - please get rid of the annoying and poorly designed logo at the top of the page. It's unnecessary.

I like this idea! thank you because you help mehow to bcome a good student.

title: Talk:How To Become A Good Student


text:
User:Pengson

Hi. I am a 2nd year bio-engineering major at the University of California, San Diego.

I enjoy tinkering with mechanics, such as bicycles, skateboards or otherwise.

title: User:Pengson


text:
User talk:Acastro~enwikibooks

Guide to First Year Teaching
Yes, naming convention in this book is okay. Plese don't sign your name in book pages - authors should be mentioned once, in separate chapter (I see you already have one, that's fine).

You can add nice navigation to your book - see Template messages/Navigation. --Derbeth talk 07:43, 18 January 2006 (UTC)

Trouble With Mandy
I was poking through the ophaned pages and stumbled across Trouble With Mandy. I was about to put it up for Votes for Deletion when I noticed it might belong to your Guide to First Year Teaching. You should probably have a look at it and see if it belongs to that book or some other you know about. --JMRyan 01:51, 1 February 2006 (UTC)

Your account will be renamed
Hello,

The developer team at Wikimedia is making some changes to how accounts work, as part of our on-going efforts to provide new and better tools for our users like cross-wiki notifications. These changes will mean you have the same account name everywhere. This will let us give you new features that will help you edit and discuss better, and allow more flexible user permissions for tools. One of the side-effects of this is that user accounts will now have to be unique across all 900 Wikimedia wikis. See the announcement for more information.

Unfortunately, your account clashes with another account also called Acastro. To make sure that both of you can use all Wikimedia projects in future, we have reserved the name Acastro~enwikibooks that only you will have. If you like it, you don't have to do anything. If you do not like it, you can pick out a different name.

Your account will still work as before, and you will be credited for all your edits made so far, but you will have to use the new account name when you log in.

Sorry for the inconvenience.

Yours, Keegan Peterzell Community Liaison, Wikimedia Foundation 22:55, 17 March 2015 (UTC)

Renamed
 This account has been renamed as part of single-user login finalisation. If you own this account you can |log in using your previous username and password for more information. If you do not like this account's new name, you can choose your own using this form after logging in: . -- Keegan (WMF) (talk) 04:28, 19 April 2015 (UTC)

title: User talk:Acastro~enwikibooks


text:
User talk:59.161.4.123

Please stop adding nonsense to Wikibooks. It is considered vandalism. If you would like to experiment, use the sandbox. Thank you.

title: User talk:59.161.4.123


text:
Statistics/Numerical Methods/Optimization

Introduction
In the following we will provide some notes on numerical optimization algorithms. As there are numerous methods out there, we will restrict ourselves to the so-called Gradient Methods. There are basically two arguments why we consider this class as a natural starting point when thinking about numerical optimization algorithms. On the one hand, these methods are really workhorses in the field, so their frequent use in practice justifies their coverage here. On the other hand, this approach is highly intuitive in the sense that it somewhat follow naturally from the well-known properties of optima. In particular we will concentrate on three examples of this class: the Newtonian Method, the Method of Steepest Descent and the class of Variable Metric Methods, nesting amongst others the Quasi Newtonian Method.

Before we start we will nevertheless stress that there does not seem to be a "one and only" algorithm but the performance of specific algorithms is always contingent on the specific problem to be solved. Therefore both experience and "trial-and-error" are very important in applied work. To clarify this point we will provide a couple of applications where the performance of different algorithms can be compared graphically. Furthermore a specific example on Maximum Likelihood Estimation can be found at the end. Especially for statisticians and econometricians the Maximum Likelihood Estimator is probably the most important example of having to rely on numerical optimization algorithms in practice.

Theoretical Motivation
Any numerical optimization algorithm has solve the problem of finding "observable" properties of the function such that the computer program knows that a solution is reached. As we are dealing with problems of optimization two well-known results seem to be sensible starting points for such properties.

If f is differentiable and $$x^\star$$ is a (local) minimum, then

$$ (1a) \quad Df(x^\star) = 0 $$

i.e. the Jacobian $$ D f(x) $$ is equal to zero

and

If f is twice differentiable and $$ x^\star $$ is a (local) minimum, then

$$ (1b) \quad x^{T}D^2 f(x^\star)x \geq 0 $$

''i.e. the Hessian $$ D^2 f(x) $$ is [http://en.wikipedia.org/wiki/Positive-definite_matrix pos. semidefinite].''

In the following we will always denote the minimum by $$ x^\star $$. Although these two conditions seem to represent statements that help in finding the optimum $$ x^\star $$, there is the little catch that they give the implications of $$ x^\star $$ being an optimum for the function $$ f $$. But for our purposes we would need the opposite implication, i.e. finally we want to arrive at a statement of the form: "If some condition $$ g(f(x^\star))$$ is true, then $$ x^\star $$ is a minimum". But the two conditions above are clearly not sufficient in achieving this (consider for example the case of $$ f(x) = x^3 $$, with $$ Df(0) = D^2 f(0) = 0 $$ but $$ x^{\star} \neq 0 $$). Hence we have to look at an entire neighborhood of $$ x^\star $$ as laid out in the following sufficient condition for detecting optima:

If $$ Df(x^\star) = 0 $$ and $$ x^{T}D^2f(z)x \geq 0, \forall x \in \mathbb{R}^n $$ and $$ z \in \mathcal{B}(x^\star, \delta)$$, then: $$x^\star$$ is a local minimum.

Proof: For $$ x \in \mathcal{B}(x^\star, \delta) $$ let $$ z=x^\star + t(x-x^\star) \in \mathcal{B} $$. The Taylor approximation yields: $$ f(x) - f(x^\star) = 0 + \frac{1}{2}(x-x^\star)^{T}D^2 f(z)(x-x^\star) \geq 0 $$, where $$ \mathcal{B}(x^\star, \delta)$$ denotes an open ball around $$ x^\star $$, i.e. $$ \mathcal{B}(x^\star, \delta) = \{x : ||x - x^\star|| \leq \delta \} $$ for $$ \delta > 0 $$.

In contrast to the two conditions above, this condition is sufficient for detecting optima - consider the two trivial examples

$$ f(x) = x^3 $$ with $$ Df(x^\star = 0) = 0 $$ but $$ x^{T}D^2f(z)x = 6 z x^2 \not\geq 0 \quad (e.g. \,\,z = -\frac{\delta}{2})$$

and

$$f(x) = x^4$$ with $$ Df(x^\star = 0) = 0$$ and $$x^{T}D^2f(z)x = 12 z^2 x^2 \geq 0 \quad \forall z$$.

Keeping this little caveat in mind we can now turn to the numerical optimization procedures.

Numerical Solutions
All the following algorithms will rely on the following assumption:

(A1) The set $$ N(f,f(x^{(0)}) = \{x \in \mathbb{R}^n | f(x) \leq f(x^{(0)})\}$$ is compact

where $$ x^{(0)} $$ is some given starting value for the algorithm. The significance of this assumption has to be seen in the Weierstrass Theorem which states that every compact set contains its supremum and its infimum. So (A1) ensures that there is some solution in $$ N(f,f(x^{(0)}) $$. And at this global minimum $$ x^\star $$ it of course holds true that $$ D(f(x^\star)) = 0 $$. So - keeping the discussion above in mind - the optimization problem basically boils down to the question of solving set of equations $$ D(f(x^\star)) = 0 $$.

The Direction of Descent
The problems with this approach are of course rather generically as $$ D(f(x^\star)) = 0 $$ does hold true for maxima and saddle points as well. Hence, good algorithms should ensure that both maxima and saddle points are ruled out as potential solutions. Maxima can be ruled out very easily by requiring $$ f(x^{(k+1)}) < f(x^{(k)}) $$ i.e. we restrict ourselves to a sequence $$ \{x^{(k)} \}_{k} $$ such that the function value decreases in every step. The question is of course if this is always possible. Fortunately it is. The basic insight why this is the case is the following. When constructing the mapping $$ x^{(k+1)} = \varphi(x^{(k)}) $$ (i.e. the rule how we get from $$x^{(k)}$$ to $$x^{(k+1)}$$) we have two degrees of freedoms, namely

 * the direction $$ d^{(k)} $$ and

 * the step length $$\sigma^{(k)}$$.

Hence we can choose in which direction we want to move to arrive at $$x^{(k+1)}$$ and how far this movement has to be. So if we choose $$d^{(k)}$$ and $$\sigma^{(k)}$$ in the "right way" we can effectively ensure that the function value decreases. The formal representation of this reasoning is provided in the following

Lemma: If $$ d^{(k)} \in \mathbb{R}^n $$ and $$ Df(x)^{T}d^{(k)} < 0$$ then: $$\exists \bar{\sigma} > 0$$ such that

$$ f(x + \sigma^{(k)} d^{(k)}) < f(x) \quad \forall \sigma \in (0,\bar{\sigma}) $$

Proof: As $$Df(x)^{T} d^{(k)} < 0$$ and $$Df(x)^{T} d^{(k)} = \lim_{\sigma \rightarrow 0} \frac{f(x + \sigma^{(k)} d^{(k)}) - f(x)}{\sigma^{(k)}}$$, it follows that $$f(x + \sigma^{(k)} d^{(k)}) < f(x)$$ for $$\sigma^{(k)}$$ small enough.

The General Procedure of Descending Methods
A direction vector $$d^{(k)}$$ that satisfies this condition is is called a Direction of Descent. In practice this Lemma allows us to use the following procedure to numerically solve optimization problems.

1. Define the sequence $$ \{x^{(k)} \}_{k} $$ recursively via $$ x^{(k+1)} = x^{(k)} + \sigma^{(k)} d^{(k)}$$

2. Choose the direction $$d^{(k)}$$ from local information at the point $$x^{(k)}$$

3. Choose a step size $$\sigma^{(k)}$$ that ensures convergence of the algorithm.

4. Stop the iteration if $$|f(x^{(k+1)}) - f(x^{(k)})| < \epsilon$$ where $$\epsilon > 0$$ is some chosen tolerance value for the minimum

This procedure already hints that the choice of $$d^{(k)}$$ and $$\sigma^{(k)}$$ are not separable, but rather dependent. Especially note that even if the method is a descending method (i.e. both $$d^{(k)}$$ and $$\sigma^{(k)}$$ are chosen according to Lemma 1) the convergence to the minimum is not guaranteed. At a first glance this may seem a bit puzzling. If we found a sequence $$ \{x^{(k)} \}_{k} $$ such that the function value decreases at every step, one might think that at some stage, i.e. in the limit of k tending to infinity we should reach the solution. Why this is not the case can be seen from the following example borrowed from W. Alt (2002, p. 76).

Example 1
$$f(x) = x^2$$, let the starting value be $$x^{(0)} = 1$$, consider a (constant) direction vector $$d^{(k)}=-1$$ and choose a step width of $$\sigma^{(k)} = (\frac{1}{2})^{k+2}$$. Hence the recursive definition of the sequence $$\{x^{(k)} \}_{k}$$ follows as
 * Consider the following example which does not converge although it is clearly descending. Let the criterion function be given by

$$(2) \quad x^{(k+1)} = x^{(k)} + (\frac{1}{2})^{k+2} (-1) = x^{(k-1)} - \left(\frac{1}{2}\right)^{k+1} - \left(\frac{1}{2}\right)^{k+2} = x^{(0)} - \sum_{j=0}^{k} \left(\frac{1}{2}\right)^{j+2}. $$

Note that $$ x^{(k)} > 0 \,\, \forall \,\, k$$ and hence $$ f(x^{(k+1)}) < f(x^{(k)}) \,\, \forall \,\,k$$, so that it is clearly a descending method. Nevertheless we find that

$$(3) \quad \lim_{k \rightarrow \infty}x^{(k)} = \lim_{k \rightarrow \infty} x^{(0)} - \sum_{j=0}^{k-1} \left(\frac{1}{2}\right)^{j+2} = \lim_{k \rightarrow \infty} 1 - \frac{1}{4}\left(\frac{1-\left(\frac{1}{2}\right)^{k}}{\frac{1}{2}}\right) = \lim_{k \rightarrow \infty} \frac{1}{2} + \left(\frac{1}{2}\right)^{k+1} = \frac{1}{2} \neq 0 = x^\star. $$

The reason for this non-convergence has to be seen in the stepsize $$\sigma^{(k)}$$ decreasing too fast. For large k the steps $$x^{(k+1)} - x^{(k)}$$ get so small that convergence is precluded. Hence we have to link the stepsize to the direction of descend $$d^{(k)}$$.

Efficient Stepsizes
The obvious idea of such a linkage is to require that the actual descent is proportional to a first order approximation, i.e. to choose $$\sigma^{(k)}$$ such that there is a constant $$c_1 > 0$$ such that

$$ (4) \quad f(x^{(k)} + \sigma^{(k)}d^{(k)}) - f(x^{(k)}) \leq c_1 \sigma^{(k)} D(f(x^{(k)})) d^{(k)} < 0. $$

Note that we still look only at descending directions, so that $$ Df(x^{(k)})^{T}d^{(k)} < 0 $$ as required in Lemma 1 above. Hence, the compactness of $$ N(f,f(x^{(k)})) $$ implies the convergence of the LHS and by (4)

$$ (5) \quad \lim_{k \rightarrow \infty} \sigma^{(k)} D(f(x^{(k)})) d^{(k)} = 0. $$

Finally we want to choose a sequence $$ \{x^{(k)} \}_{k} $$ such that $$ \lim_{k \rightarrow \infty}D(f(x^{(k)})) = 0 $$ because that is exactly the necessary first order condition we want to solve. Under which conditions does (5) in fact imply $$ \lim_{k \rightarrow \infty}D(f(x^{(k)})) = 0 $$? First of all the stepsize $$ \sigma^{(k)} $$ must not go to zero too quickly. That is exactly the case we had in the example above. Hence it seems sensible to bound the stepsize from below by requiring that

$$ (6) \quad \sigma^{(k)} \geq -c_{2} \frac{Df(x^{(k)})^{T}d^{(k)}}{|| d^{(k)}||^{2}} > 0 $$

for some constant $$c_2 > 0$$. Substituting (6) into (5) finally yields

$$ (7) \quad f(x^{(k)} + \sigma^{(k)}d^{(k)}) - f(x^{(k)}) \leq -c \left(\frac{Df(x^{(k)})^{T}d^{(k)}}{|| d^{(k)}||}\right)^{2}, \quad c = c_1 c_2 $$

where again the compactness of $$ N(f,f(x^{(k)})) $$ ensures the convergence of the LHS and hence

$$ (8) \quad \lim_{k \rightarrow \infty} -c (\frac{Df(x^{(k)})^{T}d^{(k)}}{|| d^{(k)}||})^{2} = \lim_{k \rightarrow \infty} \frac{Df(x^{(k)})^{T}d^{(k)}}{|| d^{(k)}||} = 0 $$

Stepsizes that satisfy (4) and (6) are called efficient stepsizes and will be denoted by $$\sigma_{E}^{(k)}$$. The importance of condition (6) is illustrated in the following continuation of Example 1.

Example 1 (continued)

 * Note that it is exactly the failure of (6) that induced Example 1 not to converge. Substituting the stepsize of the example into (6) yields

$$(6.1) \quad \sigma^{(k)} = \left(\frac{1}{2}\right)^{(k+2)} \geq -c_{2} \frac{2x^{(k)}(-1)}{1} = c_{2}\cdot2(\frac{1}{2} + \left(\frac{1}{2})^{k+1}\right) \Leftrightarrow \frac{1}{4(1+2^{(k)})} \geq c_{2} > 0 $$

so there is no constant $$c_{2} > 0$$ satisfying this inequality for all k as required in (6). Hence the stepsize is not bounded from below and decreases too fast. To really acknowledge the importance of (6), let us change the example a bit and assume that $$\sigma^{(k)} = \left(\frac{1}{2}\right)^{k+1}$$. Then we find that

$$(6.2) \quad \lim_{k \rightarrow \infty} x^{(k+1)} = \lim_{k \rightarrow \infty}x^{(0)} - \frac{1}{2}\sum_{i}\left(\frac{1}{2}\right)^{i} = \lim_{k \rightarrow \infty}\left(\frac{1}{2}\right)^{k+1} = 0 = x^\star, $$

i.e. convergence actually does take place. Furthermore recognize that this example actually does satisfy condition (6) as

$$(6.3) \quad \sigma^{(k)} = \left(\frac{1}{2}\right)^{(k+1)} \geq -c_{2} \frac{2x^{(k)}(-1)}{1} = c_{2}\cdot 2\left(\frac{1}{2}\right)^{k} \Leftrightarrow \frac{1}{4} \geq c_{2} >0. $$

Choosing the Direction d
We have already argued that the choice of $$\sigma^{(k)}$$ and $$d^{(k)}$$ is intertwined. Hence the choice of the "right" $$d^{(k)}$$ is always contingent on the respective stepsize $$\sigma^{(k)}$$. So what does "right" mean in this context? Above we showed in equation (8) that choosing an efficient stepsize implied

$$ (8') \quad \lim_{k \rightarrow \infty} -c (\frac{Df(x^{(k)})^{T}d^{(k)}}{|| d^{(k)}||})^{2} = \lim_{k \rightarrow \infty} \frac{Df(x^{(k)})^{T}d^{(k)}}{|| d^{(k)}||} = 0.$$

The "right" direction vector will therefore guarantee that (8') implies that

$$ (9) \quad \lim_{k \rightarrow \infty} Df(x^{(k)}) = 0$$

as (9) is the condition for the chosen sequence $$ \{x^{(k)} \}_{k} $$ to converge. So let us explore what directions could be chosen to yield (9). Assume that the stepsize $$\sigma_{k}$$ is efficient and define

$$(10) \quad \beta^{(k)} = \frac{Df(x^{(k)})^{T}d^{(k)}}{|| Df(x^{(k)})|| ||d^{(k)}||} \quad \Leftrightarrow \quad \beta^{(k)}|| Df(x^{(k)})|| = \frac{Df(x^{(k)})^{T}d^{(k)}}{|| d^{(k)}||} $$

By (8') and (10) we know that

$$(11) \quad \lim_{k \rightarrow \infty} \beta^{(k)}|| Df(x^{(k)})|| = 0. $$

So if we bound $$\beta^{(k)}$$ from below (i.e. $$\beta^{(k)} \leq - \delta < 0$$), (11) implies that

$$(12) \quad \lim_{k \rightarrow \infty} \beta^{(k)}|| Df(x^{(k)})|| = \lim_{k \rightarrow \infty} || Df(x^{(k)})|| = \lim_{k \rightarrow \infty} Df(x^{(k)}) = 0, $$

where (12) gives just the condition of the sequence $$ \{x^{(k)} \}_{k} $$ converging to the solution $$x^{\star}$$. As (10) defines the direction vector $$ d^{(k)} $$ implicitly by $$ \beta^{(k)} $$, the requirements on $$ \beta^{(k)} $$ translate directly into requirements on $$ d^{(k)} $$.

Why Gradient Methods?
When considering the conditions on $$ \beta^{(k)} $$ it is clear where the term Gradient Methods originates from. With $$ \beta^{(k)} $$ given by

$$ \beta_{k} = \frac{D(f(x)) d^{(k)}}{|| Df(x^{(k)}) || || d^{(k)} ||} = \cos(Df(x^{(k)}),d^{(k)}) $$

we have the following result

Given that $$\sigma^{(k)}$$ was chosen efficiently and $$d^{(k)}$$ satisfies

$$(13) \quad \cos(Df(x^{(k)}),d^{(k)}) = \beta_{k} \leq - \delta < 0 $$

we have

$$(14) \quad \lim_{k \rightarrow \infty} Df(x^{(k)}) \rightarrow 0 $$

Hence: Convergence takes place if the angle between the negative gradient at $$x^{(k)}$$ and the direction $$d^{(k)}$$ ''is consistently smaller than the right angle. Methods relying on $$d^{(k)}$$ satisfying (13) are called Gradient Methods.''

In other words: As long as one is not moving orthogonal to the gradient and if the stepsize is chosen efficiently, Gradient Methods guarantee convergence to the solution $$x^{\star}$$.

Some Specific Algorithms in the Class of Gradient Methods
Let us now explore three specific algorithms of this class that differ in their respective choice of $$d^{(k)}$$.

The Newtonian Method
The Newtonian Method is by far the most popular method in the field. It is a well known method to solve for the roots of all types of equations and hence can be easily applied to optimization problems as well. The main idea of the Newtonian method is to linearize the system of equations to arrive at

$$(15) \quad g(x) = g(\hat{x}) + Dg(\hat{x})^{T}(x-\hat{x}) = 0. $$

(15) can easily be solved for x as the solution is just given by (assuming $$Dg(\hat{x})^{T} $$ to be non-singular)

$$(16) \quad x = \hat{x} - [Dg(\hat{x})^{T}]^{-1}g(\hat{x}). $$

For our purposes we just choose $$g(x)$$ to be the gradient $$Df(x)$$ and arrive at

$$ (17) \quad d_{N}^{(k)} = x^{(k+1)} - x^{(k)} = - [D^2f(x^{(k)})]^{-1}Df(x^{(k)}) $$

where $$ d_{N}^{(k)} $$ is the so-called Newtonian Direction.

Properties of the Newtonian Method
Analyzing (17) elicits the main properties of the Newtonian method:

 * If $$D^2f(x^{(k)})$$ is positive definite, $$d_{N}^{k}$$ is a direction of descent in the sense of Lemma 1.

 * The Newtonian Method uses local information of the first and second derivative to calculate $$d_{N}^{k}$$.

 * As

$$ (18) \quad x^{(k+1)} = x^{(k)} + d_{N}^{(k)} $$

the Newtonian Method uses a fixed stepsize of $$ \sigma^{(k)} = 1 $$. Hence the Newtonian method is not necessarily a descending method in the sense of Lemma 1. The reason is that the fixed stepsize $$ \sigma^{(k)} = 1 $$ might be larger than the critical stepsize $$ \bar{\sigma_{k}} $$ given in Lemma 1. Below we provide the Rosenbrock function as an example where the Newtonian Method is not descending.

 * The Method can be time-consuming as calculating $$ [D^2f(x^{(k)})]^{-1} $$ for every step k can be cumbersome. In applied work one could think about approximations. One could for example update the Hessian only every sth step or one could rely on local approximations. This is known as the Quasi-Newtonian-Method and will be discussed in the section about Variable Metric Methods.

 * To ensure the method to be decreasing one could use an efficient stepsize $$ \sigma_{E}^{(k)} $$ and set

$$(19) \quad x^{(k+1)} = x^{(k)} - \sigma_{E}^{(k)}d_{N}^{(k)} = x^{(k)} - \sigma_{E}^{(k)} [D^2 f(x^{k})]^{-1} Df(x^{(k)}) $$

Method of Steepest Descent
Another frequently used method is the Method of Steepest Descent. The idea of this method is to choose the direction $$d^{(k)}$$ so that the decrease in the function value f is maximal. Although this procedure seems at a first glance very sensible, it suffers from the fact that it uses effectively less information than the Newtonian Method by ignoring the Hessian's information about the curvature of the function. Especially in the applications below we will see a couple of examples of this problem.

The direction vector of the Method of Steepest Descent is given by

$$ (20) \quad d_{SD}^{(k)} = argmax_{d : ||d|| = r} \{-Df(x^{(k)})^{T}d \} = argmin_{d : ||d|| = r} \{Df(x^{(k)})^{T}d \} = -r \frac{Df(x)}{|| Df(x) ||} $$

Proof: By the Cauchy-Schwartz Inequality it follows that

$$ (21) \quad \frac{Df(x)^{T}d}{|| Df(x) || ||d||} \geq -1 \quad \Leftrightarrow \quad Df(x)^{T}d \geq -r || Df(x) ||. $$

Obviously (21) holds with equality for $$d^{(k)} = d_{SD}^{(k)}$$ given in (20).

Note especially that for $$r = || Df(x) ||$$ we have $$d_{SD}^{(k)} = - Df(x^{(k)})$$, i.e. we just "walk" in the direction of the negative gradient. In contrast to the Newtonian Method the Method of Steepest Descent does not use a fixed stepsize but chooses an efficient stepsize $$\sigma_{E}^{(k)}$$. Hence the Method of Steepest Descent defines the sequence $$ \{x^{(k)} \}_{k} $$ by

$$ (22) \quad x^{(k+1)} = x^{(k)} + \sigma_{E}^{(k)} d_{SD}^{(k)}, $$

where $$\sigma_{E}^{(k)}$$ is an efficient stepsize and $$d_{SD}^{(k)}$$ the Direction of Steepest Descent given in (20).

Properties of the Method of Steepest Descent

 * With $$d_{SD}^{(k)} = -r \frac{Df(x)}{|| Df(x)||}$$ the Method of Steepest Descent defines a direction of descent in the sense of Lemma 1, as

$$Df(x)^{T}d_{SD}^{(k)} = Df(x)^{T}\left(-r \frac{Df(x)}{|| Df(x)||}\right) = - \frac{r}{|| Df(x)||}Df(x)^{T}Df(x) < 0. $$

 * The Method of Steepest Descent is only locally sensible as it ignores second order information.

 * Especially when the criterion function is flat (i.e. the solution $$x^\star$$ lies in a "valley") the sequence defined by the Method of Steepest Descent fluctuates wildly (see the applications below, especially the example of the Rosenbrock function).

 * As it does not need the Hessian, calculation and implementation of the Method of Steepest Descent is easy and fast.

Variable Metric Methods
A more general approach than both the Newtonian Method and the Method of Steepest Descent is the class of Variable Metric Methods. Methods in this class rely on the updating formula

$$ (23) \quad x^{k+1} = x^{k} - \sigma_{E}^{(k)} [A^{k}]^{-1} Df(x^{k}). $$

If $$A^{k}$$ is a symmetric and positive definite matrix, (23) defines a descending method as $$[A^{k}]^{-1}$$ is positive definite if and only if $$A^{k}$$ is positive definite as well. To see this: just consider the spectral decomposition

$$ (24) \quad A^{k} = \Gamma \Lambda \Gamma^{T} $$

where $$\Gamma$$ and $$\Lambda$$ are the matrices with eigenvectors and eigenvalues respectively. If $$ A^{k}$$ is positive definite, all eigenvalues $$\lambda_{i}$$ are strictly positive. Hence their inverse $$\lambda_{i}^{-1}$$ are positive as well, so that $$[A^{k}]^{-1} = \Gamma \Lambda^{-1} \Gamma^{T}$$ is clearly positive definite. But then, substitution of $$d^{(k)} = [A^{k}]^{-1} Df(x^{k})$$ yields

$$ (25) \quad Df(x^{k})^{T}d^{(k)} = -Df(x^{k})^{T}[A^{k}]^{-1}Df(x^{k}) \equiv - v^{T} [A^{k}]^{-1} v \leq 0, $$

i.e. the method is indeed descending. Up to now we have not specified the matrix $$A^{k}$$, but is easily seen that for two specific choices, the Variable Metric Method just coincides with the Method of Steepest Descent and the Newtonian Method respectively.

 * For $$A^{k} = \mathcal{I}$$ (with $$\mathcal{I}$$ being the identity matrix) it follows that

$$ (22') \quad x^{k+1} = x^{k} - \sigma_{E}^{(k)} Df(x^{k})$$

which is just the Method of Steepest Descent.

 * For $$A^{k} = D^{2}f(x^{k})$$ it follows that

$$ (19') \quad x^{k+1} = x^{k} - \sigma_{E}^{(k)} [D^{2}f(x^{k})]^{-1}Df(x^{k})$$

which is just the Newtonian Method using a stepsize $$\sigma_{E}^{(k)}$$.

The Quasi Newtonian Method
A further natural candidate for a Variable Metric Method is the Quasi Newtonian Method. In contrast to the standard Newtonian Method it uses an efficient stepsize so that it is a descending method and in contrast to the Method of Steepest Descent it does not fully ignore the local information about the curvature of the function. Hence the Quasi Newtonian Method is defined by the two requirements on the matrix $$A^{k}$$:

 * $$A^{k}$$ should approximate the Hessian $$D^{2}f(x^{k})$$ to make use of the information about the curvature and

 * the update $$A^{k} \rightarrow A^{k+1}$$ should be easy so that the algorithm is still relatively fast (even in high dimensions).

To ensure the first requirement, $$A^{k+1}$$ should satisfy the so-called Quasi-Newtonian-Equation

$$ (26) \quad A^{k+1}(x^{(k+1)} - x^{(k)}) = Df(x^{(k+1)})-Df(x^{(k)}) $$

as all $$A^{k}$$ satisfying (26) reflect information about the Hessian. To see this, consider the function $$g(x)$$ defined as

$$ (27) \quad g(x) = f(x^{k+1})+Df(x^{k+1})^{T}(x - x^{k+1})+\frac{1}{2}(x-x^{k+1})^{T}A^{k+1}(x - x^{k+1}). $$

Then it is obvious that $$g(x^{k+1}) = f(x^{k+1})$$ and $$Dg(x^{k+1}) = Df(x^{k+1})$$. So $$g(x)$$ and $$f(x)$$ are reasonably similar in the neighborhood of $$x^{(k+1)}$$. In order to ensure that $$g(x)$$ is also a good approximation at $$x^{(k)}$$, we want to choose $$A^{k+1} $$ such that the gradients at $$x^{(k)}$$ are identical. With

$$(28) \quad Dg(x^{k}) = Df(x^{k+1}) - A^{k+1} (x^{k+1} - x^{k})$$

it is clear that $$Dg(x^{k}) = Df(x^{k})$$ if $$ A^{k+1}$$ satisfies the Quasi Newtonian Equation given in (26). But then it follows that

$$ (29) \quad A^{k+1} (x^{k+1} - x^{k}) = Df(x^{k+1}) - Dg(x^{k}) = Df(x^{k+1}) - Df(x^{k}) = D^2 f(\lambda x^{(k)} + (1-\lambda)x^{(k+1)})(x^{k+1} - x^{k}). $$

Hence as long as $$x^{(k+1)}$$ and $$x^{(k)}$$ are not too far apart, $$A^{k+1}$$ satisfying (26) is a good approximation of $$D^2 f(x^{(k)})$$.

Let us now come to the second requirement that the update of the $$A^{k}$$ should be easy. One specific algorithm to do so is the so-called BFGS-Algorithm. The main merit of this algorithm is the fact that it uses only the already calculated elements $$\{x^{(k)}\}_{k}$$ and $$\{Df(x^{(k)})\}_{k}$$ to construct the update $$A^{(k+1)}$$. Hence no new entities have to be calculated but one has only to keep track of the x-sequence and sequence of gradients. As a starting point for the BFGS-Algorithm one can provide any positive definite matrix (e.g. the identity matrix or the Hessian at $$x^{(0)}$$). The BFGS-Updating-Formula is then given by

$$ (30) \quad A^{k} = A^{k-1} - \frac{(A^{k-1})^{T}\gamma_{k-1}^{T}\gamma_{k-1}A^{k-1}}{\gamma_{k-1}^{T}A^{k-1}\gamma_{k-1}} + \frac{\Delta_{k-1}\Delta_{k-1}^{T}}{\Delta_{k-1}^{T}\gamma_{k-1}} $$

where $$\Delta_{k-1} = Df(x^{(k)}) - Df(x^{(k-1)})$$ and $$\gamma_{k-1} = x^{(k)} - x^{(k-1)}$$. Furthermore (30) ensures that all $$A^{k}$$ are positive definite as required by Variable Metric Methods to be descending.

Properties of the Quasi Newtonian Method

 * It uses second order information about the curvature of $$f(x)$$ as the matrices $$A^{k}$$ are related to the Hessian $$D^{2}f(x)$$.

 * Nevertheless it ensures easy and fast updating (e.g. by the BFGS-Algorithm) so that it is faster than the standard Newtonian Method.

 * It is a descending method as $$A^{k}$$ are positive definite.

 * It is relatively easy to implement as the BFGS-Algorithm is available in most numerical or statistical software packages.

Applications
To compare the methods and to illustrate the differences between the algorithms we will now evaluate the performance of the Steepest Descent Method, the standard Newtonian Method and the Quasi Newtonian Method with an efficient stepsize. We use two classical functions in this field, namely the Himmelblau and the Rosenbrock function.

Application I: The Himmelblau Function
The Himmelblau function is given by

$$ (31) \quad f(x,y) = (x^2 + y - 11)^2 + (x + y^2 - 7)^2 $$

This fourth order polynomial has four minima, four saddle points and one maximum so there are enough possibilities for the algorithms to fail. In the following pictures we display the contour plot and the 3D plot of the function for different starting values.

In Figure 1 we display the function and the paths of all three methods at a starting value of $$(2, -4)$$. Obviously the three methods do not find the same minimum. The reason is of course the different direction vector of the Method of Steepest Descent - by ignoring the information about the curvature it chooses a totally different direction than the two Newtonian Methods (see especially the right panel of Figure 1).

Consider now the starting value $$(4.5, -0.5)$$, displayed in Figure 2. The most important thing is of course that now all methods find different solutions. That the Method of Steepest Descent finds a different solution than the two Newtonian Methods is again not that surprising. But that the two Newtonian Methods converge to different solution shows the significance of the stepsize $$\sigma$$. With the Quasi-Newtonian Method choosing an efficient stepsize in the first iteration, both methods have different stepsizes and direction vectors for all iterations after the first one. And as seen in the picture: the consequence may be quite significant.

Application II: The Rosenbrock Function
The Rosenbrock function is given by

$$ (32) \quad f(x,y) = 100(y - x^2)^2 + (1-x)^2 \ $$

Although this function has only one minimum it is an interesting function for optimization problems. The reason is the very flat valley of this U-shaped function (see the right panels of Figures 3 and 4). Especially for econometricians this function may be interesting because in the case of Maximum Likelihood estimation flat criterion functions occur quite frequently. Hence the results displayed in Figures 3 and 4 below seem to be rather generic for functions sharing this problem.

My experience when working with this function and the algorithms I employed is that Figure 3 (given a starting value of $$(2,-5)$$) seems to be quite characteristic. In contrast to the Himmelblau function above, all algorithms found the same solution and given that there is only one minimum this could be expected. More important is the path the different methods choose as is reflects the different properties of the respective methods. It is seen that the Method of Steepest Descent fluctuates rather wildly. This is due to the fact that it does not use information about the curvature but rather jumps back and forth between the "hills" adjoining the valley. The two Newtonian Methods choose a more direct path as they use the second order information. The main difference between the two Newtonian Methods is of course the stepsize. Figure 3 shows that the Quasi Newtonian Method uses very small stepsizes when working itself through the valley. In contrast, the stepsize of the Newtonian Method is fixed so that it jumps directly in the direction of the solution. Although one might conclude that this is a disadvantage of the Quasi Newtonian Method, note of course that in general these smaller stepsizes come with benefit of a higher stability, i.e. the algorithm is less likely to jump to a different solution. This can be seen in Figure 4.

Figure 4, which considers a starting value of $$(-2,-2)$$, shows the main problem of the Newtonian Method using a fixed stepsize - the method might "overshoot" in that it is not descending. In the first step, the Newtonian Method (displayed as the purple line in the figure) jumps out of the valley to only bounce back in the next iteration. In this case convergence to the minimum still occurs as the gradient at each side points towards the single valley in the center, but one can easily imagine functions where this is not the case. The reason of this jump are the second derivatives which are very small so that the step $$[Df(x^{(k)})]^{-1} Df(x^{(k)}))$$ gets very large due to the inverse of the Hessian. In my experience I would therefore recommend to use efficient stepsizes to have more control over the paths the respective Method chooses.

Application III: Maximum Likelihood Estimation
For econometricians and statisticians the Maximum Likelihood Estimator is probably the most important application of numerical optimization algorithms. Therefore we will briefly show how the estimation procedure fits in the framework developed above.

As usual let

$$(33) \quad f(Y | X; \theta) $$

be the conditional density of $$Y$$ given $$X$$ with parameter $$\theta$$ and

$$(34) \quad l(\theta; Y | X) $$

the conditional likelihood function for the parameter $$ \theta $$

If we assume the data to be independently, identically distributed (iid) then the sample log-likelihood follows as

$$(35) \quad \mathcal{L}(\theta; Y_{1}, \dots, Y_{N}) = \sum_{i}^{N} \mathcal{L}(\theta; Y_{i}) = \sum_{i}^{N} \log(l(\theta; Y_{i})). $$

Maximum Likelihood estimation therefore boils down to maximize (35) with respect to the parameter $$ \theta $$. If we for simplicity just decide to use the Newtonian Method to solve that problem, the sequence $$ \{ \theta^{(k)} \}_{k} $$ is recursively defined by

$$(36) \quad D_{\theta}\mathcal{L}(\theta^{(k+1)}) = D_{\theta}\mathcal{L}(\theta^{(k)}) + D_{\theta \theta}\mathcal{L}(\theta^{(k)})(\theta^{(k+1)} -\theta^{(k)}) = 0 \Leftrightarrow \theta^{(k+1)} = \theta^{(k)} - [D_{\theta \theta}\mathcal{L}(\theta^{(k)})]^{-1}D_{\theta}\mathcal{L}(\theta^{(k)}) $$

where $$D_{\theta}\mathcal{L}$$ and $$D_{\theta \theta}\mathcal{L}$$ denotes the first and second derivative with respect to the parameter vector $$\theta$$ and $$ [D_{\theta \theta} \mathcal{L}(\theta^{(k)})]^{-1}D_{\theta} \mathcal{L}(\theta^{(k)})$$ defines the Newtonian Direction given in (17). As Maximum Likelihood estimation always assumes that the conditional density (i.e. the distribution of the error term) is known up to the parameter $$\theta$$, the methods described above can readily be applied.

A Concrete Example of Maximum Likelihood Estimation
Assume a simple linear model

$$ (37a) \quad Y_{i} = \beta_{1} + \beta_{x} X_{i} + U_{i} $$

with $$\theta = (\beta_{1}, \beta_{2})'$$. The conditional distribution Y is then determined by the one of U, i.e.

$$ (37b) \quad p(Y_{i} - \beta_{1} - \beta_{x} X_{i}) \equiv p_{\mid X_{i}}(Y_{i}) = p(U_{i}), $$

where $$p$$ denotes the density function. Generally, there is no closed form solution of maximizing (35) (at least if U does not happen to be normally distributed), so that numerical methods have to be employed. Hence assume that U follows Student's t-distribution with m degrees of freedom so that (35) is given by

$$ (38) \quad \mathcal{L}(\theta;Y_{\mid X}) = \sum \log\left( \frac{\Gamma(\frac{m+1}{2})}{\sqrt{\pi m}\Gamma(\frac{m}{2})}(1+\frac{(y_{i} - x_{i}^{T}\beta)^2}{m})^{-\frac{m+1}{2}}\right) $$

where we just used the definition of the density function of the t-distribution. (38) can be simplified to

$$ (39) \quad \mathcal{L}(\theta;Y_{\mid X}) = N\left[\log\left(\Gamma\left(\frac{m+1}{2}\right)\right) - \log\left(\sqrt{\pi m}\Gamma\left(\frac{m}{2}\right)\right)\right] - \frac{m+1}{2} \sum \log\left(1 + \frac{(y_{i} - x_{i}^{T}\beta)^2}{m}\right) $$

so that (if we assume that the degrees of freedom m are known)

$$ (40) \quad \textit{argmax} \left\{ \mathcal{L}(\theta;Y_{\mid X}) \right\} = \textit{argmax} \left\{ -\frac{m+1}{2} \sum \log\left(1+\frac{(y_{i} - x_{i}^{T}\beta)^2}{m}\right) \right\} = \textit{argmin} \left\{ \sum \log\left(1 + \frac{(y_{i} - x_{i}^{T}\beta)^2}{m}\right) \right\}. $$

With the criterion function

$$ (41) \quad f(\beta_{1}, \beta_{2}) = \sum \log\left(1 + \frac{(y_{i} - \beta_{1} - \beta_{2}x_{i})^2}{m}\right) $$

the methods above can readily applied to calculate the Maximum Likelihood Estimator $$(\hat{\beta}_{1,ML}, \hat{\beta}_{2,ML})$$ maximizing (41).


text:
Programming Mac OS X with Cocoa for Beginners/Containers - arrays, and dictionarys

Previous Page: Building a GUI | Next Page: A more ambitious application

We have already had a brief encounter with NSDictionary, when we used one to set up a couple of attributes for drawing our "Hello World" string. Now we will have a look at it in more detail, and look at some of Cocoa's other container classes.

A container class is an object that is designed simply to look after collections of other objects. Time and again we will need to keep things in lists or tables, and the two main classes in Cocoa that do this job are NSArray and NSDictionary, and their mutable versions, NSMutableArray and NSMutableDictionary. In addition, Cocoa has some other containers such as NSSet, but for this tutorial we will not be looking at these.

Arrays
In Cocoa, NSArray and NSMutableArray objects are 'smarter' than the traditional arrays that you may be used to if you've programmed in C before. C arrays are still available if you need them, but they are very simplistic and in many cases using an NSArray or NSMutableArray will be worthwhile.

Note that an NSArray is a static array (its contents cannot be changed after it is created) while an NSMutableArray is a dynamic array (its contents can be changed after it is created). NSMutableArray is a subclass of NSArray, so it can do everything an NSArray can do and more.

If you want to keep lists of objects, NSMutableArray is generally superior to the equivalent C array. The biggest difference is that an NSMutableArray can grow (and shrink) to accommodate as many objects as you want to store. A C array has a fixed size.

Just like a C array, you refer to the elements of the array using a simple index, starting at 0 for the first element. Here are the basic access methods of NSMutableArray:

- (void)      addObject:(id)object; - (void)      insertObject:(id)object atIndex:(NSUinteger)index; - (void)      removeObject:(id)object; - (void)      removeObjectAtIndex:(NSUinteger)index; - (id)        objectAtIndex:(NSUInteger)index; - (NSUInteger) count;

Note that NSUInteger represents an unsigned integer (32 or 64-bit, depending on platform).

We must use these access methods to change what the array stores, there is no special syntax such as myarray[5] to access array elements, as there is with a C array. In some C++ frameworks, the C array syntax can be used to access elements in a dynamic array thanks to operator overloading of the [] operator, but Objective-C does not support this.

addObject: adds an object to the end of the array. insertObject:atIndex: inserts an object anywhere in the array, though be sure that the index already exists - if it's beyond the end of the array you'll get an error. Elements above the index inserted will be moved up one to accommodate the new item. removeObject: removes an object from the array, moving elements at higher index positions down to fill the gap. objectAtIndex: returns the object stored at the index, and count returns the total number of elements in the array.

When objects are added to an array, the array retains the object. When the object is removed from the array, the array releases the object. This means that objects within an array should always be valid. If the array itself is released, all the objects it contains are released too. All of Cocoa's object containers work this way.

Dictionaries
An array is great when you want to use index numbers to refer to objects, and don't mind if the indexes can change as objects come and go. You can use arrays for other types of structures too, such as queues and stacks. However, when you want to store objects in a way so that they are always associated with the same "index value", or key, a dictionary is a better bet.

NSDictionary and NSMutableDictionary are Cocoa's dictionary classes. Instead of an index, you associate objects with a key value. Later, you can retrieve the object using the key. The key never changes even as other objects come and go.

The main methods are:

- (void)   setObject:(id) object forKey:(id) key; - (id)       objectForKey:(id) key; - (void)   removeObjectForKey:(id) key; - (int)      count;

The key is itself declared to be an object, so you can use anything you like. Most commonly, you would use an NSString as the key, but you are not required to.

Internally, NSDictionary is implemented as a hash table, so accessing elements is fast.

Iterators
Often, you will want to loop over the contents of an array or dictionary, and carry out some action on each object. Cocoa declares a number of iterator or enumerator classes to make this easy. Of course, you could use a simple for(...) loop, using 'count' as a terminal value, but using an iterator is both more object-oriented, and allows quick and easy change between using an array or a dictionary for storage.

To obtain an iterator for a given container, ask the container to make it for you. The generic iterator class is NSEnumerator:

NSEnumerator* myIterator = [myArray objectEnumerator];

Because 'objectEnumerator' is a factory method, the returned iterator is autoreleased, so you don't usually need to retain it - you'll be using it once to iterate the contents of the array, then throw it away. In fact, iterators can only be used once - once you have iterated the array, there is no way to "back up" and do it again with the same iterator. Instead, you ask for a new iterator, which starts at the beginning.

To iterate, you repeatedly call the iterator's 'nextObject' method until it returns nil, meaning there are no more objects. So, an iterative loop looks like:

id anObject;

while( anObject = [myIterator nextObject]) {    /* do something useful with anObject */ }

This code would be identical whether the container was a dictionary or an array. If you used a for loop, the dictionary case would need to be quite a bit more complex than the array case, since you'd need to obtain all of the keys, then get each in turn to obtain the object.

If you wish to iterate backwards over a set of objects, ask for the reverseObjectEnumerator instead. The body of the loop doesn't change:

NSEnumerator* myIterator = [myArray reverseObjectEnumerator]; id anObject;

while( anObject = [myIterator nextObject]) {    /* do something useful with anObject */ }

Iterators and enumerators have, to a large extent, been superseded in the Objective-C language by the concept of 'fast enumeration'. Fast enumeration is a language feature that allows you to efficiently and safely enumerate over the contents of a collection using a concise syntax. The Cocoa collection classes support fast enumeration. For example

NSArray *cities = [NSArray arrayWithObjects:@"London", @"Paris", @"Rome", nil];

for (NSString *city in cities) // fast enumeration {   NSLog(@"City is %@", city); }

Cocoa enumerator classes also support fast enumeration. For example

NSArray *cities = [NSArray arrayWithObjects:@"London", @"Paris", @"Rome", nil];

for (NSString *city in [cities reverseObjectEnumerator]) // fast enumeration {   NSLog(@"City is %@", city); }

Previous Page: Building a GUI | Next Page: A more ambitious application


text:
Cryptography/Statistical Weaknesses

Letter Frequency
Whenever you consider any available language, it gives information about the frequency of letters that occur most frequently in it. The same matter is more enough for cryptanalysis (process of discovering ciphertexts) which is more beneficial when encryption is performed using the Conventional Classical Encryption Techniques.

This gives statistical information of data that cryptanalysts can use in order to decrypt the encrypted data, provided the language in which data is present is known.

title: Cryptography/Statistical Weaknesses


text:
United Nations/Preliminary

In many ways the United Nations is a product of the Second World War. It took quite a bit of effort to forge the political alliances necessary to build the Allied military force that defeated the Axis powers during this war. Even before the formal surrender of Germany and Japan, it was realized that a long-term relationship should be developed among those countries that participated in the defeat of Fascism, and a political solution that had global input needed to occur with the territories captured from the Axis powers.

During the final years of WWII, the name of the alliance had even changed, with the term United Nations being used formally for the first time as the name of the allied nations in press releases and newspaper accounts. While not formally the organization that exists today that is called the United Nations, many of the tasks that are now handled by the various Secretariats of the UN were first started at this time. There was also a strong sentiment among all of the participants of this alliance that they should not repeat the same mistakes that occurred at the end of the First World War, and in retrospect it could be argued that the framers of the United Nations have largely succeeded in that task.

Another aspect of the organization of the United Nations is the need to coordinate new participation in the war. The wartime alliance toward the end of WWII had many new countries willing to participate directly and indirectly in the combat operations, but this required formal alliance treaties independently with each of the major allied powers and grew more complex as more countries joined the alliance. It was becoming so complex that some otherwise needed wartime supplies were actually refused because of the political bureaucracy that was developing.

Some international agencies such as the International Postal Union and the International Telecommunications Union pre-date the founding of the United Nations as well, but currently receive support from the UN and are considered appendages to the larger organization as well and are governed under charters issued by the UN. There were also some aspects of the League of Nations that were absorbed into the United Nations, as most of the participants in the older League of Nations were also members of the United Nations as well. This is largely the result of a spirit of cooperation between nations that existed in the years prior to WWII, particularly for issues that didn't seem to have significant differences of opinion on how to proceed but required cooperation and standardization.

title: United Nations/Preliminary


text:
Italian/Passato prossimo

In Italian, passato prossimo is a very common tense expressing a recent, concluded action. To have an idea, you can use passato prossimo for an action you have just done, let's say from five minutes ago to two or three days ago. Despite this rule (which is not as strict as you can imagine), in northern Italy passato prossimo is also used to refer to actions which took place years ago, and the use of the correct tense for these cases, the passato remoto, is almost disappeared (but its use is compulsory when writing). On the other hand, in southern Italy, the passato prossimo tense has been dropped, and, especially in Sicily, passato remoto is used in its stead.

just an example of conjugation:

fare (to do) transitive verb, you must use "avere" to form the tense:

io    ho       fatto tu    hai      fatto egli  ha       fatto noi   abbiamo  fatto voi   avete    fatto essi  hanno    fatto

Italiano/Passato prossimo

title: Italian/Passato prossimo


text:
Italian/Passato

This Italic text tense is like the third form of the verbs in English (done, fallen...), and is used only to compose some other tenses like passato prossimo, trapassato prossimo/remoto, congiuntivo trapassato.

A general rule to form the Participio passato (not valid for the irregular verbs) is the following

for the first and the third group (-are and -ire verbs):

-drop -re -add -to

examples: dare (to give) = dato, mangiare (to eat) = mangiato, dormire (to sleep) = dormito.

for the second group (-ere verbs) -drop -ere -add -uto

cadere (to fall) = caduto; avere (to have) = avuto Remember that for the verbs in which -ere follows -sc (conoscere (to know)), the sound sh must be preserved also in the participio passato form, so an -i must be added in front of -uto:

conoscere = conosciuto

some irregular verbs:

essere (to be) =  stato

Italiano/Passato

title: Italian/Passato


text:
User talk:Rodasmith

Feel free to leave me a message. Please remember to sign your posts on talk pages. Rodasmith 17:40, 18 January 2006 (UTC)

Hi again
I started up editing lesson three, it's about connective forms and also negation. I'm beginning to think the format we're using is a bit to change retroactively, but I don't think the entire format needs to change just yet. 14:32, 22 September 2007 (UTC)

Spanish
The template does indeed belong there, if you're willing to change all the links :). As to "buenas mañanas", I don't know. I was taught it, so I added it to the Wikibook. If you know better, please change it. Regards, —Cel es tianpower háblame 16:55, 3 November 2007 (UTC)

Spanish wikibook
Check out my new vocabulary page at Spanish/Vocabulary/People. What do you think of structuring the vocabulary pages this way? Cilantrohead (talk) 00:58, 2 March 2008 (UTC)

 * It's nice for concrete nouns, but it might be challenging to get contributors to find or draw images. Besides, it's much more difficult to supply pictures for more abstract words. Also, I'd hope to see each foreign vocabulary word in such lists link to the English Wiktionary entry for that word.  Does that feeback help?  Rodasmith (talk) 22:31, 12 May 2008 (UTC)

Deletion requests
Please use to request deletion of your own pages. RFD is for Requests for deletion. -- Adrignola talk contribs 02:35, 3 March 2010 (UTC)

title: User talk:Rodasmith


text:
Talk:Physical Chemistry

do you think that the "Theoretical Chemistry" chapter should be under "Physical Chemistry" or directly under "Chemistry"? or maybe it isn't needed at all?
 * In case someone sees this discussion in the future, the answer is that "Theoretical Chemistry" is a wholly different beast than "Physical Chemistry", and could perfectly have its own book. An introductory chapter on Theoretical Chemistry here could be adequate, but no more than that --Duplode (talk) 01:23, 17 May 2010 (UTC)

Re-nameing (moving)
I moved a few of the pages according to the naming policy. This allows the chapters to be linked back to the parent book.

http://en.wikibooks.org/wiki/Wikibooks:Naming_policy

title: Talk:Physical Chemistry


text:
User talk:201.17.186.207

Please stop adding nonsense to Wikibooks. It is considered vandalism. If you would like to experiment, use the sandbox. Thank you.

title: User talk:201.17.186.207


text: User talk:86.133.206.151

title: User talk:86.133.206.151


text:
Halo

Gametypes

 * /Capture The Flag/
 * /King of the Hill/
 * /Juggernaut/
 * /Oddball/
 * /Race/
 * /Slayer/

Weapons

 * Assault Rifle
 * /Pistol/
 * /Rocket Launcher/
 * /Shotgun/
 * /Sniper Rifle/
 * /Flamethrower/ PC Only
 * /Needler/
 * /Plasma Pistol/
 * /Plasma Rifle/
 * /Fuel Rod Gun/ PC Only
 * /Frag Grenade/
 * /Plasma Grenade/
 * /Game Objective/

Vehicles

 * /Scorpion/
 * /Warthog/ With machine gun turret
 * /Rocket Warthog/ With rocket turret, PC Only
 * /Ghost/
 * /Banshee/ PC only

Levels

 * /Battle Creek/
 * /Blood Gulch/
 * /Boarding Action/
 * /Chill Out/
 * /Chiron TL-34/
 * /Damnation/
 * /Derelict/
 * /Hang Em High/
 * /Longest/
 * /Prisoner/
 * /Rat Race/
 * /Sidewinder/
 * /Wizard/
 * /Danger Canyon/ PC Only
 * /Death Island/ PC Only
 * /Gephyrophobia/ PC Only
 * /Ice Fields/ PC Only
 * /Infinity/ PC Only
 * /Timberland/ PC Only

General Tactics

 * /Vs. Scorpions/

Glitches

 * /Backpack Reload/
 * /Auto Reload Glitch/

About

 * /Glossary/

title: Halo


text:
User talk:193.108.226.11

Please do not add commercial links to Wikibooks. Wikibooks is not a vehicle for advertising or a mere collection of external links. See the welcome page if you would like to learn more about contributing to our project. Thanks. Boneheadmx 21:51, 18 January 2006 (UTC)

title: User talk:193.108.226.11


text:
Physical Chemistry/State Functions

The following demonstrates what's a state function and what's not a state function.

$$q_{rev} \;$$ is not exact differential for a gas obeying van der Waals' equation, but $$\frac{q_{rev}}{T}$$ is as demonstrated below:

$$dq_{rev} \;=\left ( \frac{\partial U}{\partial T} \right )_vdT+\left [ P_{ext}+\left ( \frac{\partial U}{\partial V} \right )_T \right ]dV$$

We assume quasistatic situation, so $$P_{ext} = P \;$$.

$$dq_{rev} \;=\left ( \frac{\partial U}{\partial T} \right )_vdT+\left [ P+\left ( \frac{\partial U}{\partial V} \right )_T \right ]dV$$

$$=C_vdT+\left [ P+\left ( \frac{\partial U}{\partial V} \right )_T \right ]dV$$

$$=C_vdT+\left [ P+\left ( \frac{a}{\overline V^2} \right ) \right ]dV$$

$$=C_vdT+\left ( \frac{RT}{\overline V-b} \right )dV$$

Now, you take the cross partial derivatives.

$$\left ( \frac{\partial C_v}{\partial V} \right )_T=0$$

$$\left ( \frac{\partial \left ( \frac{RT}{\overline V-b} \right )}{\partial T} \right )_V=\frac{R}{\overline V-b}$$

They are not equal; hence, $$q_{rev} \;$$ is not exact differential (not a state function).

However, if we take $$\frac{q_{rev}}{T}$$ it will be exact differential (a state function).

$$\frac{dq_{rev}}{T}=\frac{C_v}{T}dT+\left ( \frac{R}{\overline V-b} \right )dV$$

Take the cross partial derivatives.

$$\left ( \frac{\partial \left ( \frac{C_v}{T}\right )}{\partial V} \right )_T=0$$

$$\left ( \frac{\partial \left ( \frac{R}{\overline V-b} \right )}{\partial T} \right )_V=0$$

Both are equal making $$\frac{q_{rev}}{T}$$ exact differential (a state function).

Chimie physique/Fonction d'état

title: Physical Chemistry/State Functions


text:
UNIX Computing Security/Attacks and exploits

Suggested topics: buffer overflow, denial of service, format string attacks, man-in-the-middle attacks, penetration testing.