Wednesday 12 December 2012

Prolog Programmig: basic1

Prolog jargon is a mixture of programming terms, database terms, and logic terms.

The Prolog program is composed of predicates (procedures, record types, relations).

Each is defined by its name and a number called arity. The arity is the fixed number of arguments
(attributes, fields) the predicate has. Two predicates with the same name and different arity are
considered to be different predicates.

code example: ######################code example: ######################

% This is the syntax for comments.
% MORTAL - The first illustrative Prolog program
mortal(X) :- person(X).
person(socrates).
person(plato).
person(aristotle).
mortal_report:-
write('Known mortals are:'),nl,
mortal(X),
write(X),nl,
fail.


code example: ######################code example: ######################


In our sample program we saw three examples of predicates. They are: person/1,
mortal_report/0, and mortal/1.
 Each of these three predicates has a distinctly different flavor.
person/1 :looks like multiple data records with one data field for each.
mortal_report/0:looks like a procedure with no arguments.
mortal/1:a logical assertion or rule that is somewhere in between data and procedure.


In the example program, the predicate person/1 has three clauses. The other predicates have only
one clause.
A clause can be either a fact or a rule. The three clauses of the person/1 predicate are all facts.
The single clauses of mortal_report/0 and mortal/1 are both rules.




predicate:
clause:
backtracking:

unification:


The SWI-Prolog Tracer

use tis command to debug(trace) the prolog program:

?- trace, p(X,Y,Z).
after this command, your prolog code will be traced,
when you want to end the trace, just use notrace. then the trace function is turned off.

Compound Queries

Simple goals can be combined to form compound queries. For example, we might want to know if there is anything good to eat in the kitchen. In Prolog we might ask
    ?- location(X, kitchen), edible(X).
Whereas a simple query had a single goal, the compound query has a conjunction of goals. The comma separating the goals is read as "and."
Logically (declaratively) the  example means "Is there an X such that X is located in the kitchen and X is edible?" If the same variable name appears more than once in a query, it must have the same value in all places it appears. The query in the above example will only succeed if there is a single value of X that can satisfy both goals.
This logical query can also be interpreted procedurally, using an understanding of Prolog's execution strategy. The procedural interpretation is: "First find an X located in the kitchen, and then test to see if it is edible. If it is not, go back and find another X in the kitchen and test it. Repeat until successful, or until there are no more Xs in the kitchen."

Rules

We said earlier a predicate is defined by clauses, which may be facts or rules. A rule is no more than a stored query. Its syntax is
    head :- body.
where
head
a predicate definition (just like a fact)
:-
the neck symbol, sometimes read as "if"
body
one or more goals (a query)
For example, the compound query that finds out where the good things to eat are can be stored as a rule with the predicate name where_food/2.
    where_food(X,Y) :-  
      location(X,Y),
      edible(X).
It states "There is something X to eat in room Y if X is located in Y, and X is edible."

ust as we had multiple facts defining a predicate, we can have multiple rules for a predicate. For example, we might want to have the broccoli included in where_food/2. (Prolog doesn't have an opinion on whether or not broccoli is legitimate food. It just matches patterns.) To do this we add another where_food/2 clause for things that 'taste_yucky.'
    where_food(X,Y) :-
      location(X,Y),
      edible(X).
    where_food(X,Y) :-
      location(X,Y),
      tastes_yucky(X).
Now the broccoli shows up when we use the semicolon (;) to ask for everything.
    ?- where_food(X, kitchen).
    X = apple ;
    X = crackers ;
    X = broccoli ;
    no
Until this point, when we have seen Prolog try to satisfy goals by searching the clauses of a predicate, all of the clauses have been facts.


Using Rules

Using rules, we can solve the problem of the one-way doors. We can define a new two-way predicate with two clauses, called connect/2.
    connect(X,Y) :- door(X,Y).
    connect(X,Y) :- door(Y,X).
It says "Room X is connected to a room Y if there is a door from X to Y, or if there is a door from Y to X." Note the implied 'or' between clauses. Now connect/2 behaves the way we would like.

list_connections(Place) :-
  connect(Place, X),
  tab(2),
  write(X),
  nl,
  fail.
list_connections(_).

We now have an understanding of the fundamentals of Prolog, and it is worth summarizing what we have learned so far. We have seen the following about rules in Prolog.
  • A Prolog program is a logicbase of interrelated facts and rules.
  • The rules communicate with each other through unification, Prolog's built-in pattern matcher.
  • The rules communicate with the user through built-in predicates such as write/1.
  • The rules can be queried (called) individually from the listener.
We have seen the following about Prolog's control flow.
  • The execution behavior of the rules is controlled by Prolog's built-in backtracking search mechanism.
  • We can force backtracking with the built-in predicate fail.
  • We can force success of a predicate by adding a final clause with dummy variables as arguments and no body.
We now understand the following aspects of Prolog programming.
  • Facts in the logicbase (locations, doors, etc.) replace conventional data definition.
  • The backtracking search (list_things/1) replaces the coding of many looping constructs.
  • Passing of control through pattern matching (connect/2) replaces conditional test and branch structures.
  • The rules can be tested individually, encouraging modular program development.
  • Rules that call rules encourage the programming practices of procedure abstraction and data abstraction. (For example, look/0 doesn't know how list_things/1 works, or how the location data is stored.)
They can be used in rules as well. Here are two example predicates. One converts centigrade temperatures to Fahrenheit, the other checks if a temperature is below freezing.
    c_to_f(C,F) :-
      F is C * 9 / 5 + 32.
    
    freezing(F) :-
      F =< 32.
Here are some examples of their use.
    ?- c_to_f(100,X).
    X = 212
    yes
    
    ?- freezing(15).
    yes
    
    ?- freezing(45).
    no


Tuesday 4 December 2012

Big Data Goes to School

Big Data Goes to School

Online education is certainly not new. But what about classes with tens of thousands of students, participating from locations all over the world?

In their article about analytics in learning and education, researchers George Siemens and Phil Long offer this assessment: “Undoubtedly, analytics and big data have a significant role to play in the future of higher education. The growing role of analysis techniques and technologies in government and business sectors affirms this trend. In education the value of analytics and big data can be found in their role in guiding reform activities in higher education, and how they can assist educators in improving teaching and learning.”

Thursday 29 November 2012

李嘉诚:人最大的悲哀是无聊


 “我14岁那年,一位会看相的同乡对我母亲说:你儿子眼眸无神,骨架瘦弱,未来恐难成大器。他安分守己,终日乾乾,勉强谋生是可以的,但飞黄腾达,怕没有他的福分!”当李嘉诚缓缓走上讲台,台下掌声雷动。面对后辈新学,这位华人最知名的企业家讲起了自己的身世。
  这是长江商学院10周年庆典的现场。虽然凭借着高超的运作手段,长江商学院迅速崛起,跻身世界顶级商学院前列,但是“俱乐部门”、“明星集中营门”亦令其深陷舆论漩涡。此刻,作为“金主”,李嘉诚似乎认为有必要重申企业家的使命感,以为长江商学院提振精神。该院正是由李嘉诚基金会支持而得以兴办。
  李嘉诚接着说:“我妈妈刚刚失去丈夫不久,这番话令她多心酸。妈妈把失望放在一旁,安慰和鼓励我,说:‘阿诚!天命难算,上天一定会厚待善良、努力的人。再艰难,只要一家人相依一起就不错啦。’我当然相信母亲,但我更相信我自己!我请妈妈放心,我内心相信,只有自己双手创造的未来,才是唯一能信任的命运。”
  豪言易出,英雄难觅。彼时的李嘉诚身在战乱、父亲病故、贫穷三重合奏的悲歌中,抬头望天,亦不免忧愁。只是心中的信念如火光照前:建立更好的自己,才能建立更好的未来。
  李嘉诚认为,未来跟明天是两回事,天命和命运是不同的。明天只是新的一天,而未来是自己在一生各种偶然性中,不断选择的结果。“追求自我,努力改善自己是一股正面的驱动力,当你把思维、想象和行动谱成乐章,在科技、人文、商业无限机会中实践自我;知识、责任感和目标融汇成智慧,天命不一定是命运的蓝图。”他说。
  来上长江商学院的人很少有宿命论者。他们多是昂扬进取之士。李嘉诚的话自是说到他们心坎儿上了。前车后辙。他的成功和荣耀亦令众人痴狂。
  不过,李嘉诚话锋一转,问道:“你成功追求自我,前途光明远大,你下一阶段的追求是什么?你的价值取向,你的理想是什么?我们活着又是为了什么?世界上千千万万的人,今天依然活在悲惨、孤寂、贫病的绝望之谷,承担社会的责任,是不是我们的义务?”
  台下默然。在当今中国,追求成功,拼命挣钱,已经不需要鼓励。然而,成功之后的生活却常常令人困扰。不少富豪感到,当钱不成为问题时,生活本身却没有了意义。
  李嘉诚说,“人最大的悲哀是无聊,患上漠不关心的冷淡症,套上自命不凡的枷锁,在专业、行业和权力的高岗上,掌控庞大社会资源和机会,却失去自重心,那些沉醉在过往,滞留在今日,那些对社会问题视而不见、无动于衷的借口大王,一定被社会唾弃和淘汰。”
  他认为,有能力的人,要为人类谋幸福,这是任务。历史中有很多具有创意、有抱负的人和群体,同心合力,在追求无我中,推动社会改革进步。天地之间有一不可衡量、永恒价值的元素,只有具使命感的人才能享有。
  这是3岁小孩都懂的道理,却并非人人做得到。李嘉诚回顾过往,认为无愧于心——那个同乡看不起、瘦弱、无神的少年,一直凭努力和自信建立自我,追求无我。
  他希望,长江商学院的学子不一定做拯救世界的英雄,却一定要“谨守正知、正行、正念,应该可以高声回应社会:我们一生未曾不仁不义、不善不正”。
  这是李嘉诚一贯的想法。多年以前,他是以“赚钱的艺术”的演讲拉开长江商学院的序幕的,却最终以“奉献的艺术”做结。显然,他觉得,“善其身,济天下”的古老情怀该是长江商学院的建院之基。非为如此,不能成就一个更好的人、更好的企业家,也不可能成就一个更好的商学院。
  “我盼望,为下一代建立和守望未来,是每一位长江商学院同学的承诺,让我们一起共勉,同塑更美好的世界,世世代代能在尊严、自由和快乐中,活出我们民族的精彩。”他最后说。

Wednesday 28 November 2012

EPSRC: How to prepare a proposal


      How to prepare a proposal

To apply for funding you need to fill in an application form and prepare some accompanying documentation.

Case for support:

Other attachments:

There is some extra guidance for projects made up of multiple proposals.
Some calls for proposals may have specific requirements - these will be described in the call.

Format

Font size 11 is the minimum font that is acceptable, and the minimum margin in all directions is 2cm. For accessibility purposes, a sans-serif font style such as Arial or Helvetica should be used as these are more easily readable to those with visual impairment. For the same reason, type should be justified only on the left hand side. If your case for support exceeds the page limit, or doesn't adhere to the specified format, your proposal will not be considered. More specific instructions for the format of the case for support may be given in certain funding opportunities and calls for proposals.

Information in the public domain

Please note that if successful, some of the information you submit on the grant application form will be published through Grants on the Web (GoW). Before writing your proposal, we advise you take a look at some example grant records on these webpages so you can see what information would be made available in the public domain. Unfunded applications will not have this information published.

Applicant Guidance on constructing your proposal

Previous Research Track Record

This section (maximum two sides of A4) gives you the opportunity to demonstrate that the team involved in the proposed project has the appropriate mix of skills, expertise and experience to carry out the research. This is particularly important for multi-disciplinary proposals. You should include:
  • a summary of the results and conclusions of the applicants’ recent work in the technological/scientific area which is covered by the research proposal. Include reference to both EPSRC funded work and non-EPSRC funded work.
  • the specific expertise available for the research at the host organisation and that of any associated organisations and beneficiaries.
  • details of relevant past collaborative work with industry and/or with other beneficiaries.
  • details of where the applicants’ previous work has contributed to the UK's competitiveness or to improving the quality of life.

Description of Proposed Research and its Context

This section (maximum six sides of A4) should include:

Background

  • Introduce the topic of research and explain its academic and industrial context.
  • Demonstrate a knowledge and understanding of past and current work in the subject area in the UK and abroad.

National Importance

  • Describe the extent to which, over the long term, for example 10-50 years, the research proposed:
    • contributes to, or helps maintain the health of other research disciplines, contributes to addressing key UK societal challenges, contributes to current or future UK economic success and/or enables future development of key emerging industry(s)
    • meets national strategic needs by establishing or maintaining a unique world leading research activity (including areas of niche capability)
    • fits with and complements other UK research already funded in the area  or related areas, including the relationship to the EPSRC portfolio and our stated strategy set out in “Our Portfolio.”
The extent to which applicants are able to address each bullet point will depend on the nature of the research proposed.  Applicants should indicate how their research relates to EPSRC’s research areas and strategies (many projects will be relevant to more than 1 EPSRC research area) and complements EPSRC's current portfolio.  Information on the portfolio is available through the EPSRC's Grants on the Web (GoW).
The definition of National Importance and further details can be found at preparing new proposals to include National Importance.

Academic Impact

Describe how the research will benefit other researchers in the field and in related disciplines, both within the UK and elsewhere. What will be done to ensure that they can benefit?
  • Explain any collaboration with other researchers and their role in the project. For each Visiting Researcher, set out why they are the most appropriate person, and what they will contribute to the project.

Research Hypothesis and Objectives

  • Set out the research idea or hypothesis.
  • Explain why the proposed project is of sufficient timeliness and novelty to warrant consideration for funding.
  • Identify the overall aims of the project and the individual measurable objectives against which you would wish the outcome of the work to be assessed.

Programme and Methodology

  • Detail the methodology to be used in pursuit of the research and justify this choice.
  • Describe the programme of work, indicating the research to be undertaken and the milestones that can be used to measure its progress. The detail should be sufficient to indicate the programme of work for each member of the research team. Explain how the project will be managed.
Note: Lists of references and illustrations should be included in the six page limit and should not be submitted as additional attachments or as an annex.

Writing a good case for support

  • The case for support is your opportunity to convince your peers of  why your proposed research should be funded.
  • A good case is clear, concise and not cluttered with technical jargon. 
  • To ensure effective provision of all required information, while avoiding undue repetition within the limited space available, we recommend the following approach:
    • Impact Summary: Use this section of the Je-S application form to identify who the potential economic and societal beneficiaries might be and how they may benefit should the research objectives be fully achieved.
    • Academic Beneficiaries: Use this section of the Je-S application form to summarise how the research might benefit other researchers in the field, who might benefit in other disciplines and what will be done to ensure they benefit
    • Pathways to Impact: Use this annex to the proposal to describe activities that can be undertaken during the project to accelerate the route to the identified benefits being realised; shortening the time between discovery and use of knowledge. Also identify the additional resources needed to undertake these activities.
    • Case for Support: Include a National Importance section within this document to justify why this proposal warrants support by the UK taxpayer. Describe how the potential benefits align with national priorities, how the research relates to EPSRC’s research areas and strategies, and how it complements other research activity in the field. It is anticipated that this section should not require more than one or two paragraphs for most proposals.
  • What is exciting about the research? Try to convey this to your audience, in particular the reviewers. You need to convince these experts in your own research field about the value of your project.
  • Provide a convincing case for the originality of your proposal and describe your objectives clearly and succinctly. Proposals are not rejected just because others are doing similar work. But if you don't describe the novelty of your approach and the likelihood of success when compared with others, the value of your proposal may be questioned.
  • It's best not to leave it to EPSRC or your peers to ask the questions. Show that you have thought the proposal through and explain how it will succeed. Potential applications might be obvious to you but tell us what they are so we are left in no doubt.

Pathways to Impact (maximum two sides of A4)

In the Impact Summary, you will have described who potential beneficiaries might be, and how the research might impact them. This document is your opportunity to describe what you will actually do to facilitate this. Ideally the Pathways to Impact attachment is specific to users and beneficiaries of the research outside the academic research community, but plans for academic impact may be included where this forms part of the critical pathway towards economic and societal impact.
Detailed guidance on Pathways to Impact is available. In summary, the document should describe the kinds of impact envisaged, how the proposed research project will be managed to engage users and beneficiaries and increase the likelihood of impacts, including (wherever appropriate):
  • Methods for communications and engagement
  • Collaboration and exploitation in the most effective and appropriate manner
  • The project team’s track record in this area
  • The resources required for these activities. Please ensure these are also captured in the financial summary and the Justification of Resources.

Work Plan

The programme of work for the project should be illustrated with a simple diagrammatic work plan, for example, a PERT or Gantt chart.

Justification of Resources

In this document (up to two sides of A4) you should explain why the resources you've requested are required to undertake your research project, including implementing the impact plan. This is to help reviewers to make an informed judgement about whether the resources requested are appropriate for the research proposed.
So that you don't miss anything out, we recommend that you follow the 'cost to the proposal' headings used in the application form. For more information about what to do see how to write a justification of resources.

Curriculum Vitaes

CVs should be submitted as a separate attachment for named research staff or visiting researchers. For visiting researchers include details of previous visits or collaborations with overseas researchers. CVs must not exceed 2 sides of A4 each. You do not need to submit CVs for the principal investigator or any co-investigators.

Statements of Support

Statements of support from all project partners should be included as an attachment. There is no page limit. As part of the assessment of impact, we ask reviewers to comment on whether a collaboration is appropriate. A good statement of support can help by showing that the collaboration is genuine, and by explaining why the project partner supports the project and what they will get out of it.
Statements should be relevant to the project, written by project partners when the proposal is being prepared and dated within six months of the proposal submission date. Standard letters declaring general support are often criticised by reviewers. For more information, see guidance on what makes a good statement of support.

Letters of Support

In exceptional circumstances EPSRC will accept letters of support which do not meet the above requirements for Statements of Support. These will be cases where an organisation can not be listed as a project partner, for example when the host institution wants to detail a proposed contribution to the cost of the equipment.
However, unless there are exceptional reasons why an organisation can not meet the requirements to be a project partner, any supporting documentation should meet the above requirements for statements of support.

Equipment quotes

This information is for all equipment costing more than £10,000 (including VAT).
Equipment costs are now only mandatory for equipment costing the OJEU threshold or more. For equipment costing over £25,000 and below the OJEU threshold, it is optional to provide up to three equipment quotes.
If you are applying for equipment costing the OJEU threshold or more, you need to use EPSRC's Strategic Equipment Process.
For all items of this value, three equipment quotations must be uploaded. Equipment quotations are added within the equipment item screen, not within the attachments section. Having added the details for your item press “Save” which will then provide a link to add the attachments. Where you believe that there are less than three potential suppliers for an item you should explain this in the Justification of Resources attachment.

Technical Assessments for Facility Use

If you are planning to use a major facility as part of the proposed research, such as those funded centrally by EPSRC or a European facility, you'll  be asked to provide a technical assessment from the service provider. You should contact the facility before applying to EPSRC to check if your proposed research is feasible and obtain a technical assessment if necessary. If a technical assessment is not necessary, then you will need to upload a blank document.

Host Organisation Statements (for First Grants Only)

If you're applying through the First Grant scheme you should attach a statement from your host university, typically from your head of department. The statement should describe the commitment the university is making to the development of your research career, and confirm your appointment details and period of probation if relevant. There's no page limit. For more information see host organisation statement for first grants.

Choosing reviewers

We will approach at least one of the reviewers that you nominate. Please suggest people who are experts in the research field and/or able to judge the value of the research to people who might use its results.
It's important that we avoid any conflicts between personal interests and EPSRC's interests. You should not suggest reviewers that you have had a close working relationship with in the past (for example, your PhD supervisor), current or proposed project partners, anyone from your own organisation, or anyone with financial or personal connections with the organisations involved in the proposal. Please avoid suggesting more than one reviewer from the same organisation.

Contact us

Our portfolio managers are happy to discuss proposals before submission. We particularly encourage discussion of proposals with a complex management structure, those involving large consortia, or those consisting of more than one research theme.
Search EPSRC staff contacts

Tuesday 27 November 2012

Build a CMS in an Afternoon with PHP and MySQL


Build a CMS in an Afternoon with PHP and MySQL


php:hash_update  http://www.php.net/manual/en/function.hash.php

Where are you living now?


Where are you living now?




Thursday 22 November 2012

搞好“三农”服务 解决农村金融难题


农村金融服务是世界性难题,尤其是在我们这样一个发展中大国,人多、地少、农地经营规模狭小、发展不平衡,搞好“三农”金融服务,更为艰巨,也更有挑战性。党的十六大以来,农业银行始终致力于加强和改善“三农”金融服务,特别是近五年来,农业银行按照党中央要求,不断摸索,初步走出了一条面向“三农”和商业运作有机结合的新路子。截至2012年9月,农行涉农贷款余额1. 85万亿,比年初增加1900余亿,增速11.42%,高于农业银行全行贷款增速1. 32个百分点,比2007年增长了123%。
  为广大农民增收致富提供金融支持
  因农民居住分散,风险承受能力较弱且缺乏有效抵押物,长期以来,农民既难以从金融机构获取贷款,也难以享受便利的现代金融服务。为有效解决这一难题,农行专门推出了集储蓄、汇兑结算和小额贷款等多种功能于一体的“金穗惠农卡”和以电子服务渠道建设为主要内容的农村金融服务网络建设“惠农通”工程。截至2012年9月,农行已累计发放惠农卡1.22亿张,覆盖全国1亿余农户,覆盖率超过40%;发放农户小额贷款1051亿元,全行全口径农户贷款余额近4000亿元。同时,设立金穗“惠农通”工程服务点54.3万个,设立助农取款服务点23.6万个,布放电子机具107万台,电子机具对全国乡镇、行政村的覆盖率分别达77%、52%。依托金穗“惠农通”工程,在1043个县代理新农保、688个县代理新农合项目(合计占全国有农业人口县市区旗的50%),代理粮食直补、家电下乡补贴、农村低保等惠农项目417个,累计归集资金1402亿元、发放1076亿元,做到了“卡到户、机到村、钱到账”,让农民“足不出村”就可以享受到便捷的基础金融服务。
  积极支持现代农业发展
  农业银行积极发挥农村金融骨干和支柱作用,持续加大对农田水利等基础设施建设、农业产业化发展和农业科技进步的金融支持力度。在农田水利方面,农业银行以支持大型水利项目、江河治理、小型农田水利和新型节水高效农业等重点领域,不断加大信贷投入,截至2012年9月末,农业银行农田水利建设贷款余额达700余亿元。在农业产业化方面,农业银行以产业化龙头企业为重点,授信2300余亿元支持龙头企业扩大生产和升级技术,用信余额达1600余亿元;农行金融服务对国家级、省级农业产业化龙头企业的服务覆盖分别达到918家、4602家,覆盖率分别达73.2%和52.2%。在农业科技方面,农业银行通过加大产品服务创新力度,大力支持农业科技创新与发展,截至2012年9月末,农业银行已为全国244户农业科技企业提供信贷支持,授信总额97.49亿元,贷款余额68.12亿元;已与全部65家国家级农业科技园区建立合作关系,农业银行支持的国家农业科技园区入驻龙头企业超过4500家,推广应用新技术超过5400项、新品种超过8000个。
  大力支持城乡一体化发展
  在支持城镇化方面,适应农村城镇化大趋势,农业银行大力实施“千百工程”,在全国重点支持千家国家级农业产业化龙头企业、500个县(市)城镇化建设、千所优质县级综合医院、百个国家级农业科技园区等,并创新农村城镇化贷款等产品,大力支持小城镇基础设施建设和农民进城。截至2012年9月末,农行农村城镇化金融服务覆盖了全国50%以上的县域,贷款余额5120亿元,比2009年增长了120%。农行北京分行创新“城乡一体化综合贷款”,推动首都城中村改造建设,已累计向17个重点村发放贷款逾180亿元。在支持新农村建设方面,农业银行围绕农村基础设施和民生工程等领域的金融需求,以农村电网、道路、住房、环境建设等为重点,积极加大信贷投放,目前,农行农村基础设施贷款余额2500多亿元。福建分行开办了新农村住房建设项目贷款和新农村个人住房贷款等产品,贷款余额约70亿元。
  加强和完善服务“三农”的体制机制保障
  为确保有专门的机构、专门的人员、专门的资源专心致志服务“三农”,农业银行对“三农”和县域业务实行事业部制的管理模式。在事业部内部实行“六个单独”的运行机制,即单独的资本管理、单独的信贷政策、单独的会计核算、单独的风险拨备、单独的资金平衡、单独的考评激励等,在相关业务资源配置上向“三农”倾斜。目前,事业部改革各项工作取得了重要进展,事业部组织体系和治理机制日趋成熟,条线化的管理关系不断理顺,“六个单独”的运营机制也逐步健全。总体看,事业部改革积极效应初步显现,县域发展资源保障进一步增强。