Iterative Algorithm

An iterative algorithm takes one step at a time, ensuring that each
step makes progress
while maitining the loop
invariant
.

A paradigm shift:

View an algorithm as a sequence of Actions vs.
a sequence of Snapshots/Assertions

Understanding iterative algorithms requires understanding the
difference between a loop invariant, which is an assertion or picture of
the computation at a particular point in time, and the actions that are
required to maintain such a loop invariant.

Pre- and Postconditions:

Pre- and Postconditions provide the initial picture/assertion about the
input instance and a corresponding picture/assertion about the required
output.

Start in the Middle:

Jump into the middle of the computation and draw a static
picture/assertion about the state we would like the computation to be in
at the time.

If this assertion is sufficiently genearl, it will capture not just
this one point during the computation, but many similar points. Then it
might become a part of a loop.

Sequence of Snapshots:

Once we build up a sequence of pictures/assertions in this way, we can
see the entire path of the computation laid out before us.

Fill in the actions:

These pictures/assertions are just static snapshots of the computation.
No actions have been considered yet. The final step is to fill in the
actions (code) between consecutive assertions.

One step at a time:

Each such block of actions can be executed completely independenly of
the others. In fact, one can complete these block in any order one wants
and modify one block without worrying about the effect on others.

Being in a state in which the ith assertion holds, your task is simply
to write some simple code to do a few simple actions that change the state
of the computation so that the i+1st assertion holds.

Proof of correctness of each step:

<ith-assertion> & code i => <i+1st-assertion>

Proof of correctness of the algorithm:

Precondition & code => assertion 1

assertion 1 & code 1 => assertion 2

assertion 2 & code2 => assertion 3

...

assertion n-1 & code n-1 => assertion n

assertion n & code n => post condition

Precondition

code

assert 1

code

assert 2

code

assert 3

...

code

assert n

code

Postcondition

Iterative Algorithm,布布扣,bubuko.com

时间: 2024-08-06 03:22:10

Iterative Algorithm的相关文章

An Attempt to Understand Boosting Algorithm(s)

An Attempt to Understand Boosting Algorithm(s) WELCOME! Here you will find daily news and tutorials about R, contributed by over 573 bloggers. There are many ways tofollow us - By e-mail:  On Facebook: If you are an R blogger yourself you are invited

Spark MLlib KMeans聚类算法

1.1 KMeans聚类算法 1.1.1 基础理论 KMeans算法的基本思想是初始随机给定K个簇中心,按照最邻近原则把待分类样本点分到各个簇.然后按平均法重新计算各个簇的质心,从而确定新的簇心.一直迭代,直到簇心的移动距离小于某个给定的值. K-Means聚类算法主要分为三个步骤: (1)第一步是为待聚类的点寻找聚类中心: (2)第二步是计算每个点到聚类中心的距离,将每个点聚类到离该点最近的聚类中去: (3)第三步是计算每个聚类中所有点的坐标平均值,并将这个平均值作为新的聚类中心: 反复执行(

机器学习笔记(Washington University)- Clustering Specialization-week four

1. Probabilistic clustering model (k-means) Hard assignments do not tell the full story, capture the uncertainty k-means only considers the cluster center, not good for overlapping clusters,disparate cluster size,different shaped cluster learn weight

Pegasos: Primal Estimated sub-GrAdient Solver for SVM

Abstract We describe and analyze a simple and effective iterative algorithm for solving the optimization problem cast by Support Vector Machines (SVM). Our method alternates between stochastic gradient descent steps and projection steps. We prove tha

compiler

http://www.lingcc.com/2012/05/16/12048/ a list of compiler books — 汗牛充栋的编译器参考资料 Posted on 2012年5月16日 by Lingcc | 14 Replies 前不久,有位<编译点滴>网友询问编译器方向的参考资料.其实之前讨论过一些编译器相关的在线资料–<有写编译器的冲动?这些资料很重要>.这篇博文就来总结总结编译技术相关的各类图书资料,供各位参考.这个书列是结合本人所了解的内容整理出来的,限于

Normal Equation(正规方程)

Normal Equation Note: [8:00 to 8:44 - The design matrix X (in the bottom right side of the slide) given in the example should have elements x with subscript 1 and superscripts varying from 1 to m because for all m training sets there are only 2 featu

OPENCV(2) &mdash;&mdash; Basic Structures(一)

DataType A primitive OpenCV data type is one of unsigned char, bool,signed char, unsigned short, signed short, int, float, double, or a tuple of values of one of these types, where all the values in the tuple have the same type. 类型的命名格式: CV_<bit-dept

感知机的简单理解

一,感知机模型 1,超平面的定义 令w1,w2,...wn,v都是实数(R) ,其中至少有一个wi不为零,由所有满足线性方程w1*x1+w2*x2+...+wn*xn=v 的点X=[x1,x2,...xn]组成的集合,称为空间R的超平面. 从定义可以看出:超平面就是点的集合.集合中的某一点X,与向量w=[w1,w2,...wn]的内积,等于v 特殊地,如果令v等于0,对于训练集中某个点X: w*X=w1*x1+w2*x2+...+wn*xn>0,将X标记为一类 w*X=w1*x1+w2*x2+.

编程原理经典书籍

1 编译器整体设计与实践 1.1 龙书 – <Compilers Principles,Techniques, & Tool> 本书主页:http://dragonbook.stanford.edu/ 这本书因为封面展示了程序员努力与各种计算机难题化身而成的恶魔龙的图片而闻名. 这是编译器领域最著名的一本教材,地位相当于<算法导论>与算法课的关系. 书中对编译相关理论.编译器实现技术等等都有介绍.虽然书很厚,但惜墨如金,言简意赅. 对于一些掌握的很朦胧的基本概念,翻看此书,