关于算法:DSC-190流程的面纱

DSC 190 - “Super Homework”Due: Wednesday, June 8Write your solutions to the following problems by either typing them up or handwriting them on anotherpiece of paper. Unless otherwise noted by the problem’s instructions, show your work or provide somejustification for your answer. Homeworks are due via Gradescope at 11:59 PM.Problem 1.On Midterm 02, there was a question along the following lines. Suppose you have a data set of points X inR100 and wish to use PCA to reduce the dimensionality to 50. Consider these two approaches:? Approach 1: Run PCA once to go directly from R100 to R50, constructing a new data set Z1.? Approach 2: First run PCA with k = 75 to create an intermediate data set Z ′ of points in R75, thenrun PCA with k = 50 on Z ′ to create a new data set Z2.Is there any difference between the two approaches?The correct answer is: no, there is not. That is, Z1 = Z2. The exam’s answer key gave an intuitive geometricexplanation of the answer – here we will derive it more rigorously.In this problem, assume that X is an n× d matrix of n data points in Rd; furthermore, assume the data arecentered. Let C be the covariance matrix of the original data. Let C ′ be the covariance matrix of Z ′ (theintermediate data in approach #2). Let U75 be a 100× 75 matrix consisting of the top 75 eigenvectors of C,and let U50 be a 100× 50 matrix consisting of the top 50 eigenvectors of C. Then the new PCA features inapproach 1 are Z1 = XU50, and the intermediate PCA features in approach 2 are Z ′ = XU75.Throughout this problem you may assume for simplicity that all eigenvalues are unique.a) Recall that C ′ is the covariance matrix of Z ′, the intermediate data in approach #2. Show that C ′ isa diagonal matrix.Hint: C ′ = (Z ′)TZ ′. Also remember that for general matrices AB, (AB)T = BTAT .b) The data set Z2 is computed by multiplying the intermediate data set Z ′ by a 75 × 50 matrix U ′consisting of the top 50 eigenvectors of the covariance matrix C ′.Argue that U ′ is the matrix where entry u′ii = 1 and all other entries are zero. That is, it is a kind ofrectangular identity matrix.c) Using what we have learned above, show that Z2 = XU50, and is therefore equal to Z1.Hint: Z2 = Z ′U ′. Start by substituting for both U ′ and Z ′.Problem 2.As a data scientist you will have the opportunity to work on problems that are of great importance to society.This is not one of those problems.The menu-match dataset consists of 646 images of food from three different restaurants: an Asian restaurant,an Italian restaurant, and a soup restaurant. The data set was constructed by employees of MicrosoftResearch1.The data set is available at the following link:1http://neelj.com/projects/menumatch/1https://f000.backblazeb2.com/file/dsc-data/menu-match.npzThe file is in compressed numpy format; it can be loaded with ‘np.load‘. Once loaded, it behaves like adictionary with four keys: X_train, X_test, y_train, and y_test, corresponding to the training data, testdata, training labels, and test labels, respectively. For example, to get the training data: ...

March 1, 2023 · 4 min · jiezi

关于算法:STAT3925解释

THE UNIVERSITY OF SYDNEYMathematical Statistics: STAT3925/STAT4025 - Semester 1 - 2022Time Series Analysis : Problem Set - Week 13 (Tutorial and Revision Problems)Reminder: There will be a Computer Quiz today (Monday 23 May) at 16.00 in your class time.Submit your answers through turnitin by due time. There will be a Non-computer Quiz on Friday 27 May (Week 13) at 11.00 in your lecture time.Submit your answers through turnitin by due time.Attempt these questions before your class and discuss any issues with your tutor. ...

March 1, 2023 · 6 min · jiezi

关于算法:算法-栈与队列-用队列实现栈

力扣 225题:用队列实现栈 请你仅应用两个队列实现一个后入先出(LIFO)的栈,并反对一般栈的全副四种操作(push、top、pop 和 empty)。实现 MyStack 类:void push(int x) 将元素 x 压入栈顶。int pop() 移除并返回栈顶元素。int top() 返回栈顶元素。boolean empty() 如果栈是空的,返回 true ;否则,返回 false 。 起源:力扣(LeetCode)链接:https://leetcode.cn/problems/implement-stack-using-queues著作权归领扣网络所有。商业转载请分割官网受权,非商业转载请注明出处。解法:queue2做数据最终存储,queue1用于反转队列。每次先把queue2的旧数据移到queue1中,再把新数据加到queue2中。 class MyStack { public MyStack() { } Queue<Integer> queue1 = new ArrayDeque(); Queue<Integer>queue2 = new ArrayDeque(); public void push(int x) { while (!queue2.isEmpty()){ queue1.offer(queue2.poll()); } queue2.offer(x); while (!queue1.isEmpty()){ queue2.offer(queue1.poll()); } } public int pop() { return queue2.poll(); } public int top() { return queue2.peek(); } public boolean empty() { return queue1.isEmpty() && queue2.isEmpty(); }}/** * Your MyStack object will be instantiated and called as such: * MyStack obj = new MyStack(); * obj.push(x); * int param_2 = obj.pop(); * int param_3 = obj.top(); * boolean param_4 = obj.empty(); */

March 1, 2023 · 1 min · jiezi

关于算法:算法-栈与队列-用栈组成队列

力扣 232题 用栈实现队列 请你仅应用两个栈实现先入先出队列。队列该当反对个别队列反对的所有操作(push、pop、peek、empty):实现 MyQueue 类:void push(int x) 将元素 x 推到队列的开端int pop() 从队列的结尾移除并返回元素int peek() 返回队列结尾的元素boolean empty() 如果队列为空,返回 true ;否则,返回 false阐明:你 只能 应用规范的栈操作 —— 也就是只有 push to top, peek/pop from top, size, 和 is empty 操作是非法的。你所应用的语言兴许不反对栈。你能够应用 list 或者 deque(双端队列)来模仿一个栈,只有是规范的栈操作即可。 示例 1:输出:["MyQueue", "push", "push", "peek", "pop", "empty"][[], [1], [2], [], [], []]输入:[null, null, null, 1, 1, false]解释:MyQueue myQueue = new MyQueue();myQueue.push(1); // queue is: [1]myQueue.push(2); // queue is: [1, 2] (leftmost is front of the queue)myQueue.peek(); // return 1myQueue.pop(); // return 1, queue is [2]myQueue.empty(); // return false起源:力扣(LeetCode)链接:https://leetcode.cn/problems/implement-queue-using-stacks著作权归领扣网络所有。商业转载请分割官网受权,非商业转载请注明出处。解法:两个栈,一个用于存进入的数据,另一个存要进来的数据 ...

March 1, 2023 · 1 min · jiezi

关于算法:FIT1047网络安全系统研究

FIT1047 Introduction to computer systems, networks andsecurity - S1 2022Assignment 4 – CybersecurityPurpose In Part 1 of this assignment, students will analyse and discuss a recentvulnerability or cybersecurity attack. The report will demonstrate an understandingof related cybersecurity topics and demonstrate the ability to research informationon cybersecurity incidents.For part 2, students prepare a video presentation with slides that shows how agiven set of security controls are used in a medium-sized enterprise scenario. Thisdemonstrates an understanding of the different security controls and the ability toassess and explain their use.The assignment relates to Unit Learning Outcomes 5, 6, and 7Your task You need to choose one option and submit a report with your findings regardingthe analysis tasks for Part 1. For Part 2, you need to prepare a video presentation.The instructions below contain concrete questions you should answer in yourreport and presentation. All files (a pdf file for Part 1 and a video file along withslides in pdf for Part 2) have to be submitted via Moodle.Value 30% of your total marks for the unitParts 1 and 2 are 15% of the total marks for the unit each.Word Limit Part 1: A report with between 500 and 700 wordsPart 2: A presentation video not longer than 5 minutesDue Date Friday, June 10, 11:55 pmSubmission ● Via Moodle Assignment Submission.● Turnitin will be used for similarity checking of all submissions.AssessmentCriteriaSee rubricLate Penalties ● 10% deduction per calendar day or part thereof for up to one week● Submissions more than 7 calendar days after the due date will receive amark of zero (0) and no assessment feedback will be provided.SupportResourcesSee Moodle Assessment pageFeedback Feedback will be provided on student work via:general cohort performancespecific student feedback ten working days post submissionFACULTY OFINFORMATIONTECHNOLOGYINSTRUCTIONSPART 1 - Analyse a cybersecurity vulnerability or incident (upload 1 pdf file with the report to Moodle)Information on security problems, weaknesses and attacks can be found in many places (blogs, newsletters,experts' pages, etc.). Your task is to pick one item only from the following list (additional other sources can beadded, but need to cover the same vulnerability/incident), read the news item, look up and read the referencedsources, and finally write a report on the findings.● https://threatpost.com/samsun...● https://www.theregister.com/2...● https://arstechnica.com/infor...se-the-same-old-trick-to-bypass-mfa/● https://arstechnica.com/infor...to-crack-crypto-keys-found-in-the-wild/● https://nakedsecurity.sophos....d-update-now/● https://www.theverge.com/2022...oting● https://arstechnica.com/infor...-runs-even-when-device-is-turned-off/● https://thehackernews.com/202...Follow the following steps to write your report ...

February 28, 2023 · 5 min · jiezi

关于算法:ACCT20002财经实践理论

Intermediate Financial ReportingACCT20002 Practice ExamSolutions of Online Practice Test for the End-of-Semester Exam Fair Value MeasurementPhilip owns land with a wool factory on it in a small town near Melbourne city. The factoryis a family business that started a century ago. The factory is currently used to produce woolscarfs and clothes, but could be redeveloped as a retail shopping centre. Philip recentlyreceived an attractive offer from property redevelopers, but he rejected the offer because hehas no intention to stop the family business.Required:Discuss how Philip should apply AASB 13 Fair Value Measurement to measure fairvalue of the land and factory. ...

February 28, 2023 · 2 min · jiezi

关于算法:CSSE72310技术重点

The University of QueenslandSchool of Information Technology and Electrical EngineeringCSSE2310/CSSE7231 — Semester 1, 2022Assignment 4 (version 1.2 - 26 May 2022)Marks: 75 (for CSSE2310), 85 (for CSSE7231)Weighting: 15%Due: 4:00pm Friday 3 June, 2022Specification changes since version 1.1 are shown in blue and are summarised at the end of the document.Introduction 1The goal of this assignment is to further develop your C programming skills, and to demonstrate your under- 2standing of networking and multithreaded programming. You are to create two programs. One – dbserver 3– is a networked database server that takes requests from clients, allowing them to store, retrieve and delete 4string-based key/value pairs. The other – dbclient – is a simple network client that can query the database 5managed by dbserver. Communication between the dbclient and dbserver is done using HTTP requests and 6responses, using a simple RESTful API. Advanced functionality such as authentication, connection limiting, 7signal handling and statistics reporting are also required for full marks. 8The assignment will also test your ability to code to a particular programming style guide, to write a library 9to a provided API, and to use a revision control system appropriately. 10Student Conduct 11This is an individual assignment. You should feel free to discuss general aspects of C programming and 12the assignment specification with fellow students, including on the discussion forum. In general, questions like 13“How should the program behave if hthis happensi?” would be safe, if they are seeking clarification on the 14specification. 15You must not actively help (or seek help from) other students or other people with the actual design, structure 16and/or coding of your assignment solution. It is cheating to look at another student’s assignment code 17and it is cheating to allow your code to be seen or shared in printed or electronic form by others. 18All submitted code will be subject to automated checks for plagiarism and collusion. If we detect plagiarism or 19collusion, formal misconduct actions will be initiated against you, and those you cheated with. That’s right, if 20you share your code with a friend, even inadvertently, then both of you are in trouble. Do not post your 21code to a public place such as the course discussion forum or a public code repository, and do not allow others 22to access your computer - you must keep your code secure. 23You must follow the following code referencing rules for all code committed to your SVN repository (not 24just the version that you submit): 25Code Origin Usage/ReferencingCode provided to you in writing this semester byCSSE2310/7231 teaching staff (e.g. code hosted on Blackboard,posted on the discussion forum, or shown in class).May be used freely without reference. (You must be ableto point to the source if queried about it.)Code you have personally written this semester forCSSE2310/7231 (e.g. code written for A1 reused in A3)May be used freely without reference. (This assumesthat no reference was required for the original use.)Code examples found in man pages on moss.May be used provided the source of the code isreferenced in a comment adjacent to that code.Code you have personally written in a previous enrolmentin this course or in another ITEE course and where thatcode has not been shared or published.Code (in any programming language) that you have takeninspiration from but have not copied.Other code – includes: code provided by teaching staff onlyin a previous offering of this course (e.g. previous A1 solution);code from websites; code from textbooks; any codewritten by someone else; and any code you have writtenthat is available to other students.May not be used. If the source of the code is referencedadjacent to the code then this will be considered codewithout academic merit (not misconduct) and will beremoved from your assignment prior to marking (whichmay cause compilation to fail). Copied code withoutadjacent referencing will be considered misconduct andaction will be taken.261 Version 1.2Uploading or otherwise providing the assignment specification or part of it to a third party including online 27tutorial and contract cheating websites is considered misconduct. The university is aware of these sites and 28they cooperate with us in misconduct investigations. 29The course coordinator reserves the right to conduct interviews with students about their submissions, for 30the purposes of establishing genuine authorship. If you write your own code, you have nothing to fear from this 31process. If you are not able to adequately explain your code or the design of your solution and/or be able to 32make simple modifications to it as requested at the interview, then your assignment mark will be scaled down 33based on the level of understanding you are able to demonstrate. 34In short - Don’t risk it! If you’re having trouble, seek help early from a member of the teaching staff. 35Don’t be tempted to copy another student’s code or to use an online cheating service. You should read and 36understand the statements on student misconduct in the course profile and on the school web-site: https: 37//www.itee.uq.edu.au/itee-student-misconduct-including-plagiarism 38Specification – dbclient 39The dbclient program provides a commandline interface to allow access to a subset of the dbserver’s capabil- 40ities, in particular it permits only the setting and retrieving of key/value pairs. It does not support dbserver 41authentication, or deletion of key/value pairs. Note that you will need to read the dbserver specification 42below also to fully understand how the programs communicate. 43dbclient does not need to be multithreaded. 44Command Line Arguments 45Your dbclient program is to accept command line arguments as follows: 46./dbclient portnum key [value] 47• The portnum argument indicates which localhost port dbserver is listening on – either numerical or the 48name of a service. 49• The key argument specifies the key to be read or written. 50• The value argument, if provided, specifies the value to be written to the database for the corresponding 51key. If value is not provided, then dbclient will read the value from the database. 52• Any additional arguments are to be silently ignored. 53dbclient Behaviour 54If insufficient command line arguments are provided then dbclient should emit the following message (termi- 55nated by a newline) to stderr and exit with status 1: 56Usage: dbclient portnum key [value]If the correct number of arguments is provided, then further errors are checked for in the order below. 57Restrictions on the key value 58The key value must not contain any spaces or newlines. If it does then dbclient should emit the following 59message (terminated by a newline) to stderr and exit with status 1: 60dbclient: key must not contain spaces or newlinesThe key (and associated value) may be empty strings. The value associated with a key may contain any character 61other than a null character. 62Connection error 63If dbclient is unable to connect to the server on the specified port of localhost, it shall emit the following 64message (terminated by a newline) to stderr and exit with status 2: 65dbclient: unable to connect to port Nwhere N should be replaced by the argument given on the command line. 662 Version 1.2GETting key/value pairs 67If no value argument is specified, then dbclient shall send a GET HTTP request to the dbserver for the 68specified key in the public database. The HTTP request will look like this: 69GET /public/<key> HTTP/1.1where <key> is replaced by the requested database key. Note that the request (first) line must be terminated by 70a carriage-return line-feed (CRLF) sequence (CRLF = \r\n) and be followed by a similarly-terminated blank 71line. There is no body part necessary in the request. 72If the server returns a 200 (OK) response, then dbclient shall emit the returned value string to stdout 73(with a terminating newline), and exit with status 0. 74If the server returns any other response (e.g. 404 Not Found) or the connection with the server is lost, then 75dbclient shall emit no output, and exit with status 3. 76PUTting key/value pairs 77If value is specified, then dbclient shall attempt to set the corresponding key/value pair, using a PUT HTTP 78request as follows (see the Communication protocol section below for details): 79PUT /public/<key> HTTP/1.1Content-Length: <N><value>where <key> and <value> are replaced with the required key and value strings respectively, and <N> is replaced 80by the number of bytes in <value>. As always, lines in a HTTP request should be terminated by a CRLF 81sequence. The body part of the request must be the unmodified value part of the key-value pair – no newlines 82are present unless they are part of the value. 83If the server returns a 200 (OK) response, then dbclient shall exit with status 0. If the server returns any 84other response (e.g. 404 Not Found or 503 Service Unavailable) or the connection with the server is lost, then 85dbclient shall exit with status 4. 86dbclient example usage 87Setting and reading values from the database (assuming the dbserver is listening on port 49152): 88$ ./dbclient 49152 mykey myvalue$ echo $?0$ ./dbclient 49152 mykeymyvalue$ echo $?0Using shell quoting for values containing spaces and/or newlines: 89$ ./dbclient 49152 key "my long valuespread over two lines"$ ./dbclient 49152 keymy long valuespread over two linesAttempting to read a missing key: 90$ ./dbclient 49152 badkey$ echo $?33 Version 1.2Failed attempt to write a key/value pair: 91$ ./dbclient 49152 somekey somevalue$ echo $?4$ ./dbclient 49152 somekey$ echo $?3Specification – dbserver 92dbserver is a networked database server, capable of storing and returning text-based key/value pairs. Client 93requests and server responses are communicated over HTTP. 94The GET operation permits a client to query the database for the provided key. If present, the server returns 95the corresponding stored value. 96The PUT operation permits a client to store a key/value pair. If a value is already stored for the provided 97key, then it is replaced by the new value. 98The DELETE operation permits a client to delete a stored key/value pair. 99dbserver must implement at least one database instance, known as public, which can be accessed by any 100connecting client without authentication. 101For advanced functionality and additional marks, dbserver must manage a second database instance, called 102private, access to which is only permitted if the client provides the correct authentication string in the HTTP 103request headers. This functionality will be described in detail below. 104Command Line Arguments 105Your dbserver program is to accept command line arguments as follows: 106./dbserver authfile connections [portnum] 107In other words, your program should accept two mandatory arguments (authfile and connections), and 108one optional argument which is the port number to listen on. 109The authfile argument is the name of a text file, the first line of which is to be used as an authentication 110string (see below for details). 111The connections argument indicates the maximum number of simultaneous client connections to be per- 112mitted. If this is zero, then there is no limit to how many clients may connect (other than operating system 113limits which we will not test). 114The portnum argument, if specified, indicates which localhost port dbserver is to listen on. If the port 115number is absent, then dbserver is to use an ephemeral port. 116Important: Even if you do not implement the authentication or connection limiting functionality, your 117program must still correctly handle command lines which include those arguments (after which it can ignore 118any provided values – you will simply not receive any marks for those features). 119Program Operation 120The dbserver program is to operate as follows: 121• If the program receives an invalid command line then it must print the message: 122Usage: dbserver authfile connections [portnum]to stderr, and exit with an exit status of 1. 123Invalid command lines include (but may not be limited to) any of the following: 124– no authfile or connections number specified 125– the connections argument is not a non-negative integer 126– the port number argument (if present) is not an integer value, or is an integer value and is not either 127zero, or in the range of 1024 to 65535 inclusive 128– too many arguments are supplied 1294 Version 1.2• If portnum is missing or zero, then dbserver shall attempt to open an ephemeral localhost port for 130listening. Otherwise, it shall attempt to open the specific port number. 131• If authfile cannot be opened for reading, or the first line is empty then dbserver shall emit the following 132message to stderr and terminate with exit status 2: 133dbserver: unable to read authentication string• If portnum is missing or zero, then dbserver shall attempt to open an ephemeral localhost port for 134listening. Otherwise, it shall attempt to open the specific port number. If the authentication string can be 135read but dbserver is unable to listen on either the ephemeral or specific port, it shall emit the following 136message to stderr and terminate with exit status 3: 137dbserver: unable to open socket for listening• Once the port is opened for listening, dbserver shall print the port number to stderr, followed by a 138single newline character, and then flush the output. In the case of an ephemeral port, the actual 139port number obtained shall be printed, not zero. 140• Upon receiving an incoming client connection on the port, dbserver shall spawn a new thread to handle 141that client (see below for client thread handling). 142• If specified (and implemented), dbserver must keep track of how many client connections have been 143made, and must not let that number exceed the connections parameter. See below on client handling 144threads for more details on how this limit is to be implemented. 145• Note that all error messages must be terminated by a single newline character. 146• The dbserver program should not terminate under normal circumstances, nor should it block or otherwise 147attempt to handle SIGINT. 148• Note that your dbserver must be able to deal with any clients using the correct communication protocol, 149not just dbclient. In particular, note that dbclient will only send one request per connection but other 150clients may send multiple requests per connection. 151Client handling threads 152A client handler thread is spawned for each incoming connection. This client thread must then wait for HTTP 153requests, one at a time, over the socket. The exact format of the requests is described in the Communication 154protocol section below. 155To deal with multiple simultaneous client requests, your dbserver will need some sort of mutual exclusion 156structure around access to your key-value store. 157Once the client disconnects or there is a communication error on the socket or a badly formed request is 158received then the client handler thread is to close the connection, clean up and terminate. (A properly formed 159request for an unavailable service shall be rejected with a Bad Request response – it will not result in termination 160of the client thread.) 161SIGHUP handling (Advanced) 162Upon receiving SIGHUP, dbserver is to emit (and flush) to stderr statistics reflecting the program’s operation 163to-date, specifically 164• Total number of clients connected (at this instant) 165• The total number of clients that have connected and disconnected since program start 166• The total number of authentication failures (since program start) 167• The total number of successful GET requests processed (since program start) 168• The total number of successful PUT requests received (since program start) 169• The total number of successful DELETE requests received (since program start) 1705 Version 1.2The required format is illustrated below. 171Listing 1: dbserver SIGHUP stderr output sampleConnected clients:4Completed clients:20Auth failures:4GET operations:4PUT operations:15DELETE operations:0Note that to accurately account these statistics and avoid race conditions, you will need some sort of mutual 172exclusion structure protecting the variables holding these statistics. 173Client connection limiting (Advanced) 174If the connections feature is implemented and a non-zero command line argument is provided, then dbserver 175must not permit more than that number of simultaneous client connections to the database. dbserver shall 176maintain a connected client count, and if a client beyond that limit attempts to connect, dbserver shall send 177a 503 (Service Unavailable) HTTP response to that client and immediately terminate the connection. A client 178that connects and is immediately disconnected in this way is not counted in the number of clients for statistics 179purposes. 180Program output 181Other than error messages, the listening port number, and SIGHUP-initiated statistics output, dbserver is not 182to emit any output to stdout or stderr. 183Communication protocol 184The communication protocol uses HTTP. The client (dbclient, or other program such as netcat) shall send 185HTTP requests to the server, as described below, and the server (dbserver) shall send HTTP responses as 186described below. The connection between client and server is kept alive between requests. Supported request 187types are GET, PUT and DELETE requests. 188Additional HTTP header lines beyond those specified may be present in requests or responses and must be 189ignored by the respective server/client. Note that interaction between dbclient and dbserver is synchronous – a 190single client can only have a single request underway at any one time. This greatly simplifies the implementation 191of dbclient and the dbserver client-handling threads. 192• Request: GET /public/key HTTP/1.1 193– Description: the client is requesting the value associated with the provided key, from the public 194database instance. 195– Request 196∗ Request Headers: none expected, any headers present will be ignored by dbserver. 197∗ Request Body: none, any request body will be ignored 198– Response 199∗ Response Status: either 200 (OK) or 404 (Not Found). 200 will be returned if the provided key 200exists in the database, otherwise 404 will be returned. 201∗ Response Headers: the Content-Length header with correct value is required (number of bytes 202in the response body), other headers are optional. 203∗ Response Body: the corresponding value from the public database (or empty if the key is not 204found). 205• Request: PUT /public/key HTTP/1.1 206– Description: the client is requesting the server to write a key/value pair to the public database. 207– Request 2086 Version 1.2∗ Request Headers: the Content-Length header is expected (the value will be the number of bytes 209in the request body). This header may be omitted if the body length is zero, i.e. the value is the 210empty string. Other headers shall be ignored. 211∗ Request Body: the value to be set for the corresponding key/value pair. 212– Response 213∗ Response Status: either 200 (OK) or 500 (Internal Server Error). 200 will be returned if the 214database update operation succeeds, otherwise 500 will be returned. 215∗ Response Headers: the Content-Length: 0 header is expected (the zero value is the number of 216bytes in the response body), other headers are optional. 217∗ Response Body: None. 218• Request: DELETE /public/key HTTP/1.1 219– Description: the client is requesting the server to delete a key/value pair from the public database. 220– Request 221∗ Request Headers: none expected, any headers present will be ignored by dbserver. 222∗ Request Body: None. 223– Response 224∗ Response Status: either 200 (OK) or 404 (Not Found). 200 will be returned if the database delete 225operation succeeds, otherwise 404 will be returned. 226∗ Response Headers: the Content-Length: 0 header is expected, other headers are optional. 227∗ Response Body: None. 228• Any other (well-formed) requests should result in dbserver sending a 400 (Bad Request) HTTP response. 229Badly formed requests (i.e. the data received can not be parsed as a HTTP request) will result in the 230server disconnecting the client (as described earlier). Note that any attempt to use a space in the key will 231be interpreted as a bad request because the HTTP request line will have too many spaces. Note that it is 232permissible for the key (and the associated value) to be an empty string. 233Advanced communication protocol – authentication 234If implemented, the HTTP request Authorization: header may be used (note American spelling with a ‘z’), 235along with an authentication string, to access the private database instance. This access is identical to the 236standard protocol above, with the following extensions 237• All URL addresses become /private/key 238• The request header "Authorization: <authstring>" must be provided, where <authstring> is replaced 239by the correct authentication string. Note that leading and trailing spaces will be removed from the 240<authstring> (as per the HTTP protocol) so authentication strings with leading and/or trailing spaces 241are not supported – and will not be tested. 242• If the authentication header is not provided, or is incorrect, dbserver is to respond with the HTTP 243response “401 (Unauthorized)” 244Note that library functions are provided to you to do most of the work of parsing/constructing HTTP request- 245s/responses. See below. 246The stringstore database library and API 247An API (Application Programming Interface) for the database implementation, known as ‘StringStore’, is pro- 248vided to you in the form of a header file, found on moss in /local/courses/csse2310/include/stringstore.h. 249An implementation of stringstore is also available to you on moss, in the form of a shared library file 250(/local/courses/csse2310/lib/libstringstore.so). 251However, to receive full marks you must implement your own version of StringStore according 252to the API specified by stringstore.h. You must submit your stringstore.c and your Makefile must build 253this to your own libstringstore.so. 254This will allow you to start writing dbserver without first implementing the underlying database. 2557 Version 1.2Your dbserver must use this API and link against libstringstore.so. Note that we will use our 256libstringstore.so when testing your dbserver so that you are not penalised in the marking of dbserver for 257any bugs in your StringStore implementation. You are free to use your own libstringstore.so when testing 258yourself – see below. 259stringstore.h defines the following functions: 260Listing 2: stringstore.h contents/// Opaque type for StringStore - you'll need to define 'struct StringStore'// in your stringstore.c filetypedef struct StringStore StringStore;// Create a new StringStore instance, and return a pointer to itStringStore *stringstore_init(void);// Delete all memory associated with the given StringStore, and return NULLStringStore stringstore_free(StringStore store);// Add the given 'key'/'value' pair to the StringStore 'store'.// The 'key' and 'value' strings are copied with strdup() before being// added to the database. Returns 1 on success, 0 on failure (e.g. if// strdup() fails).int stringstore_add(StringStore store, const char key, const char *value);// Attempt to retrieve the value associated with a particular 'key' in the// StringStore 'store'.// If the key exists in the database, return a const pointer to corresponding// value string.// If the key does not exist, return NULLconst char stringstore_retrieve(StringStore store, const char *key);// Attempt to delete the key/value pair associated with a particular 'key' in// the StringStore 'store'.// If the key exists and deletion succeeds, return 1.// Otherwise, return 0int stringstore_delete(StringStore store, const char key);Note that it is not expected that your StringStore library be thread safe – the provided libstringstore.so 261is not. 262Creating shared libraries – libstringstore.so 263This section is only relevant if you are creating your own implementation of libstringstore.o. 264Special compiler and linker flags are required to build shared libraries. Here is a Makefile fragment you can 265use to turn stringstore.c into a shared library, libstringstore.so: 266Listing 3: Makefile fragment to compile and build a shared libraryCC=gccLIBCFLAGS=-fPIC -Wall -pedantic -std=gnu99 ...

February 28, 2023 · 34 min · jiezi

关于算法:COMPSCI-720分析设计

1213-1 COMPSCI 720 (21/06/2021 17:30) Adv Design and Analysis of Alg (Exam)By submitting this assessment, I agree to the following declaration: As a member of the University’s student body, I will complete this assessment in a fair, honest,responsible and trustworthy manner. This means that: · I will not seek out any unauthorised help in completing this assessment. (NB. Unauthorised helpincludes a tutorial or answer service whether in person or online, friends or family, etc.)· I will not discuss or share the content of the assessment with anyone else in any form, includingbut not limited to, Canvas, Piazza, Chegg, Facebook, Twitter, Discord or any other social mediawithin the assessment period.· I will not reproduce and/or share the content of this assessment in any domain or in any formwhere it may be accessed by a third party.· I am aware the University of Auckland may use Turnitin or any other plagiarism detectingmethods to check my content.· I declare that this assessment is my own work, except where acknowledged appropriately (e.g.,use of referencing).· I declare that this work has not been submitted for academic credit in another University ofAuckland course, or elsewhere. ...

February 28, 2023 · 8 min · jiezi

关于算法:如何在IoT物联网平台注册私有CA证书来实现X509方式设备身份认证实践类

1.前言IoT物联网平台反对应用公有数字证书进行设施接入身份认证。应用公有数字证书,须要实现如下操作:①在物联网平台注册CA证书,②将数字设施证书与设施身份相绑定。 本文介绍如何在物联网平台注册公有CA证书并给设施绑定设施证书。 限度阐明仅MQTT协定直连的设施可应用公有CA证书。目前仅华东2(上海)地区反对应用公有CA证书。应用公有CA证书时,只反对RSA算法签名的设施证书。一个阿里云账号最多可注册10个公有CA证书。2.注册公有CA证书2.1 制作公有CA证书咱们在Mac电脑上应用OpenSSL工具制作公有CA证书。命令如下: # 生成公有CA和key ,有效期10年openssl req -new -x509 -days 3650 -keyout myIoTCARoot.key -out myIoTCARoot.crt# 查看CA证书openssl x509 -noout -text -in myIoTCARoot.crt公有CA证书内容: 2.2 制作验证证书当咱们注册公有CA证书时,IoT物联网平台要求咱们同时上传应用公有CA证书对应的私钥创立的验证证书,用来证实咱们领有该公有CA证书。 查看公有证书注册码 登录IoT物联网平台控制台。在左侧导航栏,抉择设施治理 > CA证书。在CA证书治理页,单击注册CA证书。在注册CA证书对话框中,获取注册码。验证证书制作咱们同样以OpenSSL为例,制作验证证书,操作步骤如下: 生成验证证书Key# 生成验证证书openssl genrsa -out verificationCert.key 2048生成验证证书CSR,其中Common Name 需填入IoT控制台获取的公有CA证书注册码# 生成验证证书CSRopenssl req -new -key verificationCert.key -out verificationCert.csr……Common Name (e.g. server FQDN or YOUR name) []: *****7dc9a483ebbf7e6997b7b****……应用由公有CA证书私钥签名的CSR创立验证证书# 用公有CA和key签发验证证书openssl x509 -req -in verificationCert.csr -CA myIoTCARoot.crt -CAkey myIoTCARoot.key -CAcreateserial -out verificationCert.crt -days 300 -sha512# 查看验证证书内容openssl x509 -noout -text -in verificationCert.crt查看验证证书: ...

February 28, 2023 · 1 min · jiezi

关于算法:COSC2391-先进图形设计应用程序

Further ProgrammingCOSC2391Assignment 2: Graphic Design Application AssessmentType >Individual assignment; no group work. Submit online via Canvas → Assignments → Assignment 2.Marks are awarded for meeting requirements as closely as possible according to assignmentspecifications and the supplied rubric. Clarifications or updates may be made via announcements.Due Date Week 13, Friday 3rd June 11:59pm. Late submission penalty will be applied unless special considerationhas been granted.There will be 3 milestones: week 8 in-lab milestone check, week 11 in-lab milestone check and week14 post submission final interview. You will describe the key concepts adopted in your code,demonstrate code execution, and explain your code in the milestones.Marks 50 marks out of 100 for assignment 2.3 milestones (5 marks for week 8 in-lab milestone checking, 5 marks for week 11 in-lab milestonechecking, and 6 marks for week 14 post submission final interview) will add up to 16 marks in additionto the 50 marks. ...

February 28, 2023 · 11 min · jiezi

关于算法:MATH4091金融微积分算法难点

– Assignment 4 –MATH4091/7091: Financial calculusAssignment 4Semester I 2022No more questions will be added.Due Friday June 3 Weight 15%Total marks 35 marksSubmission: Softcopy (i.e. scanned copy) of your assignment by 23:59pm Friday June 3, 2022.Hardcopies are not required.Notation: “Lx.y” refers to [Lecture x, Slide y]Assignment questions (15 marks) In L8, you learned how to perform a probability measure change using Girsanov’sTheorem (statement on L8.16). In particular, the Radon-Nikody′m derivative process {Zt}t∈[0,T ]is constructed from the process {t}t∈[0,T ], and, as emphasized in class, the choice for thisprocess depends on the objective of the measure change, which in turn, depends on the pricingproblem you are dealing with (e.g. the payoff function).In constructing the P→ Q measure change for the (standard) Black-Scholes model (in L8), wewere motivated by the objective that the discounted price process{StBt}t∈[0,T ]is a martingaleunder Q.1 For this objective, t was chosen to be the constant market price of risk t = ?r .Suppose that now you want to perform a measure change from P to another probability measure,denoted by QS , under which{BtSt}t∈[0,T ]is a martingale. (Note this process is{BtSt}t∈[0,T ], not{StBt}t∈[0,T ].) We denote by{W?St}a Brownian motion under QS . The probability measure QSis often referred to as the “share measure”.a. (4 marks) Mathematically derive a formula for t used in the Radon-Nikody′m derivativeprocess {Zt}t∈[0,T ]. In your derivation, clearly express W?St (or dW?St ) in terms of Wt (ordWt) and t. (Note that t should be a constant in this case.)Find dSt and dBt under QS .b. (3 marks) Lett = (at, bt) be a self-finance portfolio ofXt = (St, Bt) under the real-worldmeasure P. Let its value process be {Vt}t∈[0,T ], where Vt = t ·Xt. Here, as usual, weassume {at}t∈[0,T ] and {bt}t∈[0,T ] are Ft-predictable processes.What can you conclude about “self-financing” under the P→ QS measure change?1As such, with this choice of t, the price process of any (admissible) portfolio of (S,B) is a martingale under Q,and hence, we arrive at the general expectation pricing formula on L8.28.MATH 4091/7091 – 1 – Duy-Minh Dang 2022– Assignment 4 –c. (4 marks) Consider a financial contract with payoff CT . Let Ct be the price at time-t ofthis contract. Prove thatCt = StEQS[CTST∣∣∣∣Ft] . (1)d. (4 marks) Suppose CT = ST ln (ST ). In this case, while it is possible to use the risk-neutralpricing formula on L8.28 (via EQ [·]), it is more convenient to use EQS , since CTST = ln (ST )which is much simpler than CT /BT .Use the pricing formula (1) to find C0.(12 marks) Let {Wt}t∈[0,T ] be a Brownian motion on a probability space (?,F ,P), and let{Ft}t∈[0,T ] be the filtration generated by this Brownian motion.Let {ht}t∈[0,T ] be an {Ft}t∈[0,T ]-predictable process satisfying EP(∫ T(ht)dt)<∞. Define ana. (7 marks) Show that Y can be decomposed into ...

February 28, 2023 · 3 min · jiezi

关于算法:活动预告-3-月-4-日2023-Meet-TVM-开年首聚

随着机器学习框架和硬件需要的一直倒退,机器学习编译成为备受关注的话题。 2023 年 3 月 4 日,由 OpenBayes贝式计算联合推出的「2023 Meet TVM:开年首聚」线下流动将在上海举办,探讨机器学习编译的当初和将来。 OpenBayes贝式计算工程副总裁姜汉将在流动上介绍如何应用 TVM 做边缘设施的模型编译和推理实际。 分享工夫:14:50-15:30内容简介: 为了在边缘端设施上不便部署模型,并晋升性能。咱们应用 TVM 实现在不同的后端上,反对对不同边缘设施的模型编译和部署。观看本场分享,你将理解: 应用 TVM 在边缘设施进行推理的实际应用 TVM auto-scheduler 进行优化模型的实际应用 TVM 后端开发的初步实际 线下参加:扫描海报中二维码跳转至流动行报名 线上参加:通过 HyperAI超神经微信视频号收看线上直播。 将来,OpenBayes贝式计算将立足机器学习编译,为新一代异构芯片嫁接经典软件生态及机器学习模型,为工业企业及高校科研提供更加疾速、易用的数据科学计算产品。

February 28, 2023 · 1 min · jiezi

关于算法:算法-链表-双指针

力扣 第2题 : 两数相加 给你两个 非空 的链表,示意两个非负的整数。它们每位数字都是依照 逆序 的形式存储的,并且每个节点只能存储 一位 数字。请你将两个数相加,并以雷同模式返回一个示意和的链表。你能够假如除了数字 0 之外,这两个数都不会以 0 结尾。 示例 1:输出:l1 = [2,4,3], l2 = [5,6,4]输入:[7,0,8]解释:342 + 465 = 807.示例 2:输出:l1 = [0], l2 = [0]输入:[0]示例 3:输出:l1 = [9,9,9,9,9,9,9], l2 = [9,9,9,9]输入:[8,9,9,9,0,0,0,1]起源:力扣(LeetCode)链接:https://leetcode.cn/problems/add-two-numbers著作权归领扣网络所有。商业转载请分割官网受权,非商业转载请注明出处。解法:双指针解释在正文代码中 class Solution { public ListNode addTwoNumbers(ListNode l1, ListNode l2) { // 1 校验node,如果l1是null,返回l2;如果l2是null,返回l1。 if(l1 == null){ return l2; }else if(l2 == null){ return l1; } // vh1,vh2是遍历指针 ListNode vh1 = l1; ListNode vh2 = l2; while(vh1 != null && vh2 != null){ int sum = vh1.val + vh2.val; if(sum < 10){ vh1.val = sum; }else { // 如果呈现加和超过10,向任一链表的下一个节点加1 vh1.val = sum%10; nextAddOne(vh1); } //判断边界 if(vh1.next == null) { vh1.next = vh2.next; break; } else if(vh2.next == null) { vh2.next = vh1.next; break; } // 筹备下一轮的内容 vh1 = vh1.next; vh2 = vh2.next; } return l1; } /** * 向链表的下一个节点加1,进位用。 */ void nextAddOne(ListNode node){ if(node.next == null){ node.next = new ListNode(1); return; } int num = node.next.val + 1; if(num < 10){ node.next.val = num; return; }else{ node.next.val = 0; nextAddOne(node.next); } }}

February 27, 2023 · 1 min · jiezi

关于算法:算法-字符串-反转字符串中的单词

力扣 151题 反转字符串中的单词 给你一个字符串 s ,请你反转字符串中 单词 的程序。单词 是由非空格字符组成的字符串。s 中应用至多一个空格将字符串中的 单词 分隔开。返回 单词 程序颠倒且 单词 之间用单个空格连贯的后果字符串。留神:输出字符串 s中可能会存在前导空格、尾随空格或者单词间的多个空格。返回的后果字符串中,单词间该当仅用单个空格分隔,且不蕴含任何额定的空格。 示例 1:输出:s = "the sky is blue"输入:"blue is sky the"示例 2:输出:s = "  hello world  "输入:"world hello"解释:反转后的字符串中不能存在前导空格和尾随空格。示例 3:输出:s = "a good   example"输入:"example good a"解释:如果两个单词间有多余的空格,反转后的字符串须要将单词间的空格缩小到仅有一个。起源:力扣(LeetCode)链接:https://leetcode.cn/problems/reverse-words-in-a-string著作权归领扣网络所有。商业转载请分割官网受权,非商业转载请注明出处。解法:双指针替换数组中的元素 class Solution { public String reverseWords(String s) { String[] strs = s.split(" "); for(int i = 0; i < strs.length/2 ; i++){ String tmp = strs[i]; strs[i] = strs[strs.length-1-i]; strs[strs.length-1-i] = tmp; } StringBuilder sb = new StringBuilder(); for(String x : strs){ if(x.length()>0) sb.append(x).append(" "); } return sb.substring(0, sb.length()-1).toString(); }}

February 27, 2023 · 1 min · jiezi

关于算法:算法-字符串-反转字符串

题目1力扣 344题, 反转字符串 编写一个函数,其作用是将输出的字符串反转过去。输出字符串以字符数组 s 的模式给出。不要给另外的数组调配额定的空间,你必须原地批改输出数组、应用 O(1) 的额定空间解决这一问题。 示例 1:输出:s = ["h","e","l","l","o"]输入:["o","l","l","e","h"]示例 2:输出:s = ["H","a","n","n","a","h"]输入:["h","a","n","n","a","H"]起源:力扣(LeetCode)链接:https://leetcode.cn/problems/reverse-string著作权归领扣网络所有。商业转载请分割官网受权,非商业转载请注明出处。解法:双指针 class Solution { public void reverseString(char[] s) { int left = 0; int right = s.length-1; while(left < right){ char t = s[left]; s[left] = s[right]; s[right] = t; left++; right--; } }}题目2力扣 541题 反转字符串II 给定一个字符串 s 和一个整数 k,从字符串结尾算起,每计数至 2k 个字符,就反转这 2k 字符中的前 k 个字符。如果残余字符少于 k 个,则将残余字符全副反转。如果残余字符小于 2k 但大于或等于 k 个,则反转前 k 个字符,其余字符放弃原样。 示例 1:输出:s = "abcdefg", k = 2输入:"bacdfeg"示例 2:输出:s = "abcd", k = 2输入:"bacd"起源:力扣(LeetCode)链接:https://leetcode.cn/problems/reverse-string-ii著作权归领扣网络所有。商业转载请分割官网受权,非商业转载请注明出处。解法:双指针 ...

February 27, 2023 · 1 min · jiezi

关于算法:通过01背包问题理解动态规划

「烤冷面讲算法」系列,每周更新:https://scriptrunz.com/zh-cn/...「一个干货技术社群」:https://scriptrunz.com/zh-cn/... 01背包问题假如你是个小偷,背着一个可装 4 磅货色的背包。你可偷盗的商品有如下 3 件: 为了让偷盗的商品价值最高,你该抉择哪些商品? 暴力搜寻暴力搜寻法会将每种组合都尝试一遍后找到最优解,不言而喻这种算法的工夫复杂度为O($2^n$),只有问题扩充到肯定规模,这个算法肯定行不通。 动静布局动静布局先解决子问题,再逐渐解决大问题。 对于背包问题,你先解决小背包(子背包)问题,再逐渐解决原来的问题。 依照这个思维,咱们尝试将背包容量逐渐放大到 4、3、2、1,计算不同容量的背包所能承载的最大价值。进而,咱们能够画进去一个表格,列代表不同容量的背包,行代表不同品种物品。 这是一个表格,也是一个行列式,咱们将这个行列式命名为 dp,dp3 的值就是题解。咱们一步步把行列式的值填满,最终行列式被齐全填满后,题解天然上不着天;下不着地。 填满行列式第一行是吉他行,这意味着咱们尝试将吉他装入背包,在每一个单元格都须要做一个决定:要不要把吉他放到背包里。第一个单元格示意背包的容量为 1 磅。吉他的分量也是 1 磅,这意味着它能装入背包!因而这个单元格蕴含吉他,价值为 ¥1500。 1234吉他1500 音响 笔记本电脑 到了下一个单元格,它示意背包的容量为 2 磅,齐全可能装下吉他!然而咱们只有一把吉他,所以总价值还是 ¥1500。同理,容量为 3、4 磅的背包总价值放弃 ¥1500 不变。 1234吉他1500150015001500音响 笔记本电脑 来到第二行,可偷的商品有吉他和音响。 音响重 4 磅,所以第二行的前三个格子只能抉择吉他,价值 ¥1500。到了第 4 个格子,咱们就能够抉择更贵的音响,总价值 ¥3000。 1234吉他1500150015001500音响1500150015003000笔记本电脑 来到第三行,可偷的商品有吉他、音响、笔记本电脑。 笔记本电脑重 3 磅,所以第 3 行的前 2 个格子只能抉择吉他,价值 ¥1500。到了第 3 个格子,咱们就能够抉择更贵的笔记本电脑,总价值 ¥2000。 ...

February 27, 2023 · 1 min · jiezi

关于算法:算法-哈希表-三数之和

力扣 15题 : 三数之和 给你一个整数数组 nums ,判断是否存在三元组 [nums[i], nums[j], nums[k]] 满足 i != j、i != k 且 j != k ,同时还满足 nums[i] + nums[j] + nums[k] == 0 。请你返回所有和为 0 且不反复的三元组。留神:答案中不能够蕴含反复的三元组。  示例 1:输出:nums = [-1,0,1,2,-1,-4]输入:[[-1,-1,2],[-1,0,1]]解释:nums[0] + nums[1] + nums[2] = (-1) + 0 + 1 = 0 。nums[1] + nums[2] + nums[4] = 0 + 1 + (-1) = 0 。nums[0] + nums[3] + nums[4] = (-1) + 2 + (-1) = 0 。不同的三元组是 [-1,0,1] 和 [-1,-1,2] 。留神,输入的程序和三元组的程序并不重要。示例 2:输出:nums = [0,1,1]输入:[]解释:惟一可能的三元组和不为 0 。示例 3:输出:nums = [0,0,0]输入:[[0,0,0]]解释:惟一可能的三元组和为 0 。起源:力扣(LeetCode)链接:https://leetcode.cn/problems/3sum著作权归领扣网络所有。商业转载请分割官网受权,非商业转载请注明出处。解法1 ,应用哈希表映射参考:算法 - 哈希表 - 两数之和 与 四数之和 ...

February 27, 2023 · 2 min · jiezi

关于算法:CITS3403-最后测试方式

CITS3403/5505 Final Test.Taking your project to the next level.This Exam is worth 50% of your final grade and must be done individually. For equity reasons, the teaching staffwill not be able to answer individual questions between the exams release and the due date. Questions may beposted to the Final Test teams channel and may be answered by teaching staff. Any communication,commentary, or discussion of the test during this period will be considered academic misconduct. Submit a zipcontaining your HTML document and any required media files to https://secure.csse.uwa.edu.a...by 5pm Wednesday, June 1, 2022Consider the challenging of launching your daily game, produced in the group project, as a live gameused by thousands of users around the world everyday. You will have to make sure the game is asengaging as possible, the code must be reliable, the servers will have to handle the traffic, and youmust respect the users data.For the final unit test, you will need to produce a HTML document describing how you might addressthese challenges. The questions must be answered with respect to the current state of your groupproject. The document should satisfy the following constrains: ...

February 27, 2023 · 5 min · jiezi

关于算法:COMPSCI-720-计算算法

COMPSCI 720, S1, 2022Assignment 4 Due: 1 June 2022, 4.00 pm NZTPlease submit a single PDF file with your solutions to Canvas. A (scanned) handwritten report is fine aslong as it is neat. Fixed-parameter algorithms in computational biology.Select a paper that describes a fixed-parameter algorithm for a problem in computational biology,read the paper, and write a report (maximum 800 words) that clearly describes the topic/problemof the paper, summarizes the result, and describes the main ideas of the fixed-parameter algorithm.Use consistent notation throughout. Any terminology not previously covered in class, needs to beintroduced formally as part of your report.For inspiration on possible papers, see the following recent review: Bulteau and Weller (2019), “Parameterizedalgorithms in bioinformatics: an overview” (available on Canvas).Please do not choose one of the two papers that we have covered in class, and attach a copy of thepaper you have read to your submission.(5 marks)rSPR distance.(a) Give two rooted binary phylogenetic X-trees T and T0such that drSPR(T , T0) = 2.(1 mark)(b) What is the rSPR distance between the following two rooted binary phylogenetic trees T and Explain your answer.(c) Let F be a maximum agreement forest for two rooted binary phylogenetic X-trees T and T0suchthat |F| = k + 1. Given T , T0, and F, there is a polynomial-time algorithm for constructinga sequence T0, T1, T2, . . . , Tk of rooted binary phylogenetic X-trees such that T0 = T , Tk = T0and, for each i ∈ {0, 1, 2, . . . , k − 1}, drSPR(Ti, Ti+1) = 1. Describe such an algorithm usingpseudocode.Tip. Have a look at the proof of Theorem 2.1. of the paper Bordewich and Semple (2004) “Onthe computational complexity of the rooted subtree prune and regraft distance”.(2.5 marks)

February 27, 2023 · 2 min · jiezi

关于算法:3805ICT先进算法

3805ICT Advanced Algorithms – Assignment 2 (100 Marks)Note:a) This assignment must be done individually.b) The programming language to be used is C++ but you may use Python to generategraphs for your reports.c) For each question requiring a C++ program you must document the algorithm andshow any test cases you used. Only submit a single Word document containingthe documentation for all questions.d) The submission time and date are as specified in the Course Profile and thesubmission method will be communicated during semester.QUESTION 1 [10 MARKS]A very large number of random numbers are added to a list. Design and implement an efficient datastructure that will maintain a separate list of the k smallest numbers that are currently in the list.Space efficiency must be O(k + n). How would you handle deletions? Perform an amortised analysisof your data structure.QUESTION 2 [10 MARKS]A simple algorithm for maze generation is to start, apart from entry and exit points, with all walls presentand randomly knock down walls until the entry and exit points are connected. Write a C++ program toimplement this algorithm for an arbitrary sized maze – test with a 50 by 88 rectangular maze.QUESTION 3 [10 MARKS]Using C++ software obtained from the internet analyse and compare the performance of Red-BlackTrees and Van Emde Boas Trees using a large number of integers. This should be done for add, find,delete and sequential access.QUESTION 4 [20 MARKS]The object of the Kevin Bacon Game is to link a movie actor to Kevin Bacon via shared movie roles.The minimum number of links is an actor’s Bacon number. For instance, Tom Hanks has a Baconnumber of 1; he was in Apollo 13 with Kevin Bacon. Sally Fields has a Bacon number of 2, becauseshe was in Forrest Gump with Tom Hanks, who was in Apollo 13 with Kevin Bacon. Almost all wellknownactors have a Bacon number of 1 or 2. Given a list of actors, with roles, write a C++ programthat does the following:(a) Finds an actor’s Bacon number.(b) Finds the actor with the highest Bacon number.(c) Finds the minimum number of links between two arbitrary actors.QUESTION 5 [50 MARKS]Design an algorithm and write a program to identify the minimum vertex covers within the complementgraphs of the supplied graphs. The table below shows the output from a current minimum vertex coversolver for these complement graphs.(a) You must actually design your own algorithm and write all program code submitted. Theprogram must be able to be run from the command line passing the target minimum vertexcover size as an argument. The naming convention for your program file is<student_number>_mvc (without the <>) and try and keep the program within a single file.2(b) As this a computationally intensive algorithm, you must use C/C++, written using all possibleoptimisations.(c) You must produce a detailed Latex/Word paper containing an Introduction, Literature Review,Algorithm Description, Experimental Results and Comparisons and a Conclusion.(d) You must produce a Power-point presentation summarising your algorithms, implementation,testing and the results of the problem and performance analysis. Do not include any code inyour powerpoint presentation.Graph Minimum Vertex Cover Successful Trials Average CPU Timebrock800_1 777 86 84.54brock800_2 776 98 74.90brock800_3 775 100 45.30brock800_4 774 100 26.75c2000.9 1,922 1 36.28c4000.5 3,982 100 142.02MANN_a45 691 100 88.76p_hat1500-1 1,488 100 1.39 ...

February 27, 2023 · 3 min · jiezi

关于算法:算法-哈希表-两数之和-与-四数之和

第一题 两数之和力扣 第一题:两数之和 给定一个整数数组 nums 和一个整数目标值 target,请你在该数组中找出 和为目标值 target  的那 两个 整数,并返回它们的数组下标。你能够假如每种输出只会对应一个答案。然而,数组中同一个元素在答案里不能反复呈现。你能够按任意程序返回答案。 示例 1:输出:nums = [2,7,11,15], target = 9输入:[0,1]解释:因为 nums[0] + nums[1] == 9 ,返回 [0, 1] 。示例 2:输出:nums = [3,2,4], target = 6输入:[1,2]示例 3:输出:nums = [3,3], target = 6输入:[0,1]起源:力扣(LeetCode)链接:https://leetcode.cn/problems/two-sum著作权归领扣网络所有。商业转载请分割官网受权,非商业转载请注明出处。办法1:循环遍历两次, 工夫复杂度 O(n*n) 办法2:哈希表映射,遍历一次,工夫复杂度 O(n) class Solution { public int[] twoSum(int[] nums, int target) { Map<Integer, Integer> map = new HashMap<>(); for(int i = 0; i < nums.length; i++){ if(map.containsKey(target-nums[i])){ return new int[]{i, map.get(target-nums[i])}; } map.put(nums[i], i); } return null; }}第二题:四数相加II力扣 454题,四数相加 ...

February 27, 2023 · 2 min · jiezi

关于算法:算法-哈希表-数组的交集

力扣 349题,两个数组的交加 给定两个数组 nums1 和 nums2 ,返回 它们的交加 。输入后果中的每个元素肯定是 惟一 的。咱们能够 不思考输入后果的程序 。 示例 1:输出:nums1 = [1,2,2,1], nums2 = [2,2]输入:[2]示例 2:输出:nums1 = [4,9,5], nums2 = [9,4,9,8,4]输入:[9,4]解释:[4,9] 也是可通过的起源:力扣(LeetCode)链接:https://leetcode.cn/problems/intersection-of-two-arrays著作权归领扣网络所有。商业转载请分割官网受权,非商业转载请注明出处。解法:Set.retainAll(Set)取汇合的交加 import java.util.*;class Solution { public int[] intersection(int[] nums1, int[] nums2) { Set<Integer> set1 = new HashSet<>(); for(int i = 0; i < nums1.length; i++) { set1.add(nums1[i]); } Set<Integer> set2 = new HashSet<>(); for(int i = 0; i < nums2.length; i++) { set2.add(nums2[i]); } set2.retainAll(set1); int[] result = new int[set2.size()]; int idx = 0; for(Integer v : set2){ result[idx++] = v; } return result; }}

February 27, 2023 · 1 min · jiezi

关于算法:BUCI057H7问题应用

BUCI057H7 page 2 of 9 Question 1 (10 marks)Provost & Fawcett have defined Data Science in terms of 9 computational problems.Define the Similarity problem in general and propose examples on multi-dimensional data.Your answer: BUCI057H7 page 3 of 9 Question 2 (10 marks)Spectral analysis can be used to reduce data dimensionality. Explain why dimensionality reduction isdesirable and how Spectral analysis can achieve it.Your answer: BUCI057H7 page 4 of 9 Question 3 (10 marks)Over D = {a, b, c, d, e}, frequency of observations gives us the following distribution:P = Pr[X=xi] = [3/8, 3/16, 1/8, 1/8, 3/16].To simplify calculations, however, we decide to adopt the “simpler” distributionQ = Pr[X=xi] = [1/2, 1/8, 1/8, 1/8, 1/8].Compute the Kullback-Leibler divergence between P and Q, defined as ...

February 27, 2023 · 2 min · jiezi

关于算法:FIT3171操作数据库原理

FIT3171 DatabasesCreating, Populating and Manipulating Database - Run Monash (RM)Purpose Students will be asked to implement, via SQL, a small database in the OracleRDBMS from a provided logical model case study, followed by the insert ofappropriate data to the created tables. Once populated the database will be usedto: carry out specified DML commands and make specified changes to thedatabase structure via SQL. This task covers learning outcomes: Apply the theories of the relational database model.Implement a relational database based on a sound database design.Manage data that meets user requirements, including queries andtransactions.Your task This is an open book, individual task. The final output for this task will be a set oftables and data implemented in the Oracle RDBMSValue 25% of your total marks for the unitDue Date Thursday, 26 May 2022, 4:30 PM (AEST) / 2:30 (MYT)Submission ● Via Moodle Assignment Submission.● FIT GitLab check ins will be used to assess history of developmentAssessmentCriteria● Application of relational database principles.● Handling of transactions and the setting of appropriate transactionboundaries.● Application of SQL statements and constructs to create and alter tablesincluding the required constraints and column comments, populate tables,modify existing data in tables, and modify the "live" database structure tomeet the expressed requirements (including appropriate use ofconstraints).Late Penalties ● 10% deduction per calendar day or part thereof for up to one week● Submissions more than 7 calendar days after the due date will receive amark of zero (0) and no assessment feedback will be provided.SupportResourcesSee Moodle Assessment pageFeedback Feedback will be provided on student work via:● general cohort performance● specific student feedback ten working days post submission● a sample solutionPage 1 of 14FACULTY OFINFORMATIONTECHNOLOGYINSTRUCTIONSRun Monash (RM) is a running carnival which is held on separate dates at various Monashcampuses during different seasons (Summer, Autumn, Winter and Spring) of the year. Thecarnival naming convention that Run Monash uses is RM Series name> . So, for example, a carnival to be held during the Autumn season at theClayton campus in 2022 will be named RM Autumn Series Clayton 2022.Anyone can attend an RM Carnival, the carnivals are open to the public as well as Monashstaff and students. A carnival is run on a particular date, in a particular location and onlylasts for one day. RM only runs one carnival on any particular date. During a carnival a rangeof events are offered from the following list (only some may be offered):● Marathon 42.2 Km● Half Marathon 21.1 Km● 10 Km Run● 5 Km Run● 3 Km Community Run/WalkRun Monash expects to offer around 10 - 20 such events across all carnivals in a given year.When a competitor initially registers for Run Monash, they are assigned a unique competitornumber. A competitor is required to provide details of an emergency contact at the time ofregistration. The relationship to the competitor can be Parent (P), Guardian (G), Partner (T)or Friend (F).When a carnival is being offered, Run Monash contacts all registered competitors andprovides details of the carnival date and what events are on offer. A competitor can onlyattend one event at a particular carnival. Every entry is assigned an entry number. The entrynumber is reused in each event. Run Monash also, on the carnival day, using official timingdevices, Run Monash records the entrants starting and finishing times.Teams are identified by a unique team name which the team manager must select whenthey first create the team. This team manager can then add/invite other competitors from thecarnival to join their team. Team names are unique only within a given carnival. A given teamname may be reused by different competitors in a different carnival as teams are recreatedfor each carnival depending on which competitors have entered an event for the carnival.Run Monash wishes to record, as part of the stored data, how many members are on eachteam. Teams may also nominate a charity for which they will raise funds, although not allteams will do so. All charities for which funds can be raised must first be approved by RunMonash. Note that an individual competitor may be supporting a charity as an individual andalso the same or a different charity as a team member.Page 2 of 14FACULTY OFINFORMATIONTECHNOLOGYA model to represent this system has been developed:The schema/insert file for creating this model (rm-schema-insert.sql) is available in thearchive ass2-student.zip - this file partially creates the Run Monash tables and populatesseveral of the tables (those shown in purple on the supplied model) - you should read thisschema carefully and be sure you understand the various data requirements. You must notalter the schema file in any manner, it must be used as supplied.Steps for working on Assignment 2Download the Assignment 2 Required Files (ass2-student.zip) archive from MoodleExtract the zip archive and place the contained files in your local (MoVE or localHDD) repository in the folder /Assignments/Ass2. Do not add the zip archive to yourlocal repo. Then add, commit and push them to the FITGitLab server.Run rm-schema-insert.sqlWrite your answer for each task in its respective file (e.g. write your answer for Task 1in T1-rm-schema.sql and so on).Save, add, commit and push the file/s regularly while you are working on theassignmentFinally, when you have completed all tasks, upload all required files from your localrepository to Moodle (if you are using MoVE you will need to download them to yourlocal HDD first - do not attempt to upload from MoVE). Check that the files you haveuploaded are the correct files (download them from Moodle into a temporary folderand check they are correct). After you are sure they are correct, submit yourassignment.Page 3 of 14FACULTY OFINFORMATIONTECHNOLOGYNote that the final SQL scripts you submit MUST NOT contain SPOOL or ECHO commands(you may include them as you work but must remove them before submission). Pleasecarefully read the Marking Guide document.TASKSENSURE your id and name are shown at the top of any file you submit.GIT STORAGEYour work for these tasks MUST be saved in your individual local working directory (repo) inthe Assignment 2 folder and regularly pushed to the FIT GitLab server to build a clear historyof development of your approach. Any submission with less than five pushes to theFITGitLab server will incur a grade penalty of 10 marks. Please note five pushes is aminimum, in practice we would expect significantly more.Before submission via Moodle you must log into the web interface of the GitLab server andensure your files are present in your individual repo.TASK 1: DDL (20 marks)For this task you are required to add to T1-rm-schema.sql, the CREATE TABLE andCONSTRAINT definitions which are missing from the supplied partial schema script in thepositions indicated by the comments in the script.The table below provides details of the meaning of the attributes in the missing four tables.You MUST use exactly the same relation and attribute names as shown in the datamodel above to name the tables and attributes which you add. The attributes must be in thesame order as shown in the model. These new DDL commands must be hand-coded, notgenerated in any manner (generated code will not be marked).Table name Attribute name MeaningEMERCONTACTec_phone Emergency contact’s phone number (unique identifier)ec_fname Emergency contact’s first nameec_lname Emergency contact’s last nameCOMPETITORcomp_no Unique identifier for a competitorcomp_fname Competitor’s first namecomp_lname Competitor’s last namecomp_gender Competitor’s gender (‘M’ for male, ‘F’ for female, or ‘U’ for‘Undisclosed’)comp_dob Competitor’s date of birthcomp_email Competitor’s emailPage 4 of 14FACULTY OFINFORMATIONTECHNOLOGYcomp_unistatus Competitor’s university student/staff status ('Y' for Yes or'N' for No)comp_phone Competitor’s phone numbercomp_ec_relationship Emergency contact relationship to competitor (‘P’ forParent, ‘G’ for Guardian, ‘T’ for Partner, or ‘F’ for Friend)ENTRYentry_no Entry number (unique for each event)entry_starttime The entrant start timeentry_finishtime The entrant finish timeTEAMteam_id Team identifier (unique)team_name Team nameteam_no_members Number of team membersTo test your code you will need to first run the provided script rm-schema-insert.sql tocreate the other required tables. rm-schema-insert.sql, at the head of the file, contains thedrop commands for all tables in this model. If you have problems with Task 1 and/or Task 2simply rerun rm-schema-insert.sql which will cause all tables to be dropped and correct theissues in your script.TASK 2: Populate Sample Data (20 marks)Before proceeding with Task 2, you must ensure you have run the file rm-schema-insert.sql(which must not be edited in any way) followed by the extra definitions that you added inTask 1 above (T1-rm-schema.sql).Load the EMERCONTACT, COMPETITOR, ENTRY, and TEAM tables with your owntest data using the supplied T2-rm-insert.sql script file, and SQL commands whichwill insert as a minimum, the following sample data:(i) 5 EMERCONTACT entries● of the 5 contacts added 3 must be contacts for more than onecompetitor(ii) 15 COMPETITOR entries● Have at least 10 competitors who are Monash student/staff● Have at least 2 competitors who are not Monash student/staff● Included at least 2 competitors who are under 18 years of age(iii) 30 ENTRY entries● Included at least 10 competitors● Included at least 6 events from 3 different carnivals● Have at least 5 competitors who join more than 2 events● Have at least 2 uncompleted entries (registration only)(iv) 5 TEAM entries● Have at least 2 teams with more than 2 members● At least one team with the same name in different carnivalsPage 5 of 14FACULTY OFINFORMATIONTECHNOLOGYIn adding this data you must ensure that the test data thoroughly tests the model assupplied, so as to ensure your schema is correct.Your inserted data must conform to the following rules:(i) You may treat all of the data that you add as a single transaction since you aresetting up the initial test state for the database.(ii) The numeric primary key values for this data should be hardcoded values (i.e. NOTmake use of sequences) and must consist of values below 100.(iii) The data added must be sensible eg. entry finish times should be after entry starttimes with a sensible running duration.For this task ONLY, Task 2, you may look up and include values for the loadedtables/data directly where required. However, if you wish, you can still use SQL to getany non-key values.In carrying out this task you must not modify any data or add any further data to thetables which were populated by the rm-schema-insert.sql script.__For all subsequent questions (Task 3 onwards) you are NOT permitted to:● manually lookup a value in the database to obtain its primary key or the highest/lowestvalue in a column,● manually calculate values (including dates/times) external to the database, e.g. on acalculator and then use such values in your answers. Any necessary calculations mustbe carried out as part of your SQL code, or● assume any particular contents in the database - rows in a table are potentially in aconstant state of changeYour answers must recognise the fact that you have been given, with the supplied insert file,only a very small sample snapshot of a multiuser database, as such you must operate on thebasis that there will be more data in all of the tables of the database than you have beengiven. Your answers must work regardless of the extra quantity of this extra "real"data and the fact that multiple users will be operating in the tables at the same time.You must take this aspect into consideration when writing SQL statements.You must ONLY use the data as provided in the text of the questions. Failure to adhere tothis requirement will result in a mark of 0 for the relevant question.Your SQL must correctly manage transactions and use sequences to generate newprimary keys for numeric primary key values (under no circumstances may a newprimary key value be hardcoded as a number or value).PL/SQL may ONLY be used for Task 5.

February 26, 2023 · 9 min · jiezi

关于算法:ELEC4630图像处理

ELEC4630 Image Processing and Computer VisionAssignment 3(Due date: Friday 3/6/2022 at 4pm) Assignment report should include coding, results, images, and a verbal description ofhow you approached the problem. Some similar solutions can be found on the internet, butyou won’t learn anything by copying these verbatim, and you may be flagged for integrityissues — none of us want this. However, in this assignment you are encouraged to findinternet solutions and modify the code significantly to match your problem. This is fineand ethical as long as you cite your sources appropriately. Also, the tutors will help youwith the coding. Most importantly, have fun. ...

February 26, 2023 · 3 min · jiezi

关于算法:算法训练LeetCode-39-组合总和-40组合总和II-131分割回文串

欢送关注集体公众号:爱喝可可牛奶 LeetCode 39. 组合总和 40.组合总和II 131.宰割回文串LeetCode 39. 组合总和剖析回溯可看成对二叉树节点进行组合枚举,分为横向和纵向 每次往sum增加新元素时,必须明确从can哪个地位开始,定义变量pos 返回条件 sum == target 或 sum > target; 横向完结条件 没有新元素能够增加了即pos<can.length; bt(can, sum, tar, pos){ if(sum == tar) add return; if(sum > tar) pos++ return; for(int i = pos; i < can.len;i++){ sum+=can[pos]; bt(can, sum, tar, i); sum-=can[pos]; }}这个回溯思考sum > tar时, pos++不应该写在第3行,这样导致回溯减掉的元素值与递归增加的不一样。而应该放在第4行for()中,只有当纵向回溯完结时(也就是很多个sum+=can[i]导致return后),横向遍历才会往右挪动;回溯第n个can[i] 回溯第n-1个can[i]; 剪枝一次回溯只能对消一层递归;每次return只是从曾经增加进sum的泛滥can[i]中减掉一个 举个栗子: sum+= n个can[i],回溯一次还剩n-1个can[i];这时要i++了;然而剩下的sum和这个i++后的新can[i]加起来可能也会超过tar,这步操作能够剪枝,防止进入新can[i]的递归; for (int i = pos; i < candidates.size() && sum + candidates[i] <= target; i++)代码class Solution { List<List<Integer>> res = new ArrayList<>(); LinkedList<Integer> path = new LinkedList(); public List<List<Integer>> combinationSum(int[] candidates, int target) { Arrays.sort(candidates); // 先进行排序 backtracking(candidates, target, 0, 0); return res; } public void backtracking(int[] candidates, int target, int sum, int idx) { // 找到了数字和为 target 的组合 if (sum == target) { res.add(new ArrayList<>(path)); return; } for (int i = idx; i < candidates.length; i++) { // 如果 sum + candidates[i] > target 就终止遍历 if (sum + candidates[i] > target) break; path.add(candidates[i]); backtracking(candidates, target, sum + candidates[i], i); path.removeLast(); // 回溯,移除门路 path 最初一个元素 } }}LeetCode 40.组合总和II剖析在原有根底上设限每个数字在每个组合中只能应用 一次 且不蕴含反复的组合 ...

February 26, 2023 · 2 min · jiezi

关于算法:算法-链表-环形链表

力扣 142题 环形链表II 环形链表 II难度中等1959给定一个链表的头节点  head ,返回链表开始入环的第一个节点。 如果链表无环,则返回 null。如果链表中有某个节点,能够通过间断跟踪 next 指针再次达到,则链表中存在环。 为了示意给定链表中的环,评测零碎外部应用整数 pos 来示意链表尾连贯到链表中的地位(索引从 0 开始)。如果 pos 是 -1,则在该链表中没有环。留神:pos 不作为参数进行传递,仅仅是为了标识链表的理论状况。不容许批改 链表。 示例 1:输出:head = [3,2,0,-4], pos = 1输入:返回索引为 1 的链表节点解释:链表中有一个环,其尾部连贯到第二个节点。示例 2:输出:head = [1,2], pos = 0输入:返回索引为 0 的链表节点解释:链表中有一个环,其尾部连贯到第一个节点。示例 3:输出:head = [1], pos = -1输入:返回 null解释:链表中没有环。要点1:应用快慢指针判断链表是否有环 ListNode slow = head;//慢指针 ListNode fast = head;//快指针 while(fast != null && fast.next != null){ slow = slow.next; //每次往前走一步 fast = fast.next.next;//每次往前走两步 if(slow == fast) {//快慢指针相遇 如果相遇,示意链表有环,但相遇点 不肯定是 第一次入环的节点。 } }要点2:如何找到第一次入环的节点?详看力扣题解 /** * Definition for singly-linked list. * class ListNode { * int val; * ListNode next; * ListNode(int x) { * val = x; * next = null; * } * } */public class Solution { public ListNode detectCycle(ListNode head) { ListNode slow = head;//慢指针 ListNode fast = head;//快指针 while(fast != null && fast.next != null){ slow = slow.next; //每次往前走一步 fast = fast.next.next;//每次往前走两步 if(slow == fast) {//快慢指针相遇 System.out.println("meet node : " + slow.val); ListNode headIndex = head; ListNode meetNode = slow; while(headIndex != meetNode) { headIndex = headIndex.next; meetNode = meetNode.next; } return meetNode; } } return null; }}

February 26, 2023 · 1 min · jiezi

关于算法:算法-链表-虚拟头结点

起源:力扣(LeetCode)链接:https://leetcode.cn/problems/... 给你一个链表的头节点 head 和一个整数 val ,请你删除链表中所有满足 Node.val == val 的节点,并返回 新的头节点 。 示例 1:输出:head = [1,2,6,3,4,5,6], val = 6输入:[1,2,3,4,5]示例 2:输出:head = [], val = 1输入:[]示例 3:输出:head = [7,7,7,7], val = 7输入:[]起源:力扣(LeetCode)链接:https://leetcode.cn/problems/remove-linked-list-elements著作权归领扣网络所有。商业转载请分割官网受权,非商业转载请注明出处。形式1/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode() {} * ListNode(int val) { this.val = val; } * ListNode(int val, ListNode next) { this.val = val; this.next = next; } * } */class Solution { public ListNode removeElements(ListNode head, int val) { if(head== null){ return head; } while(head != null && head.val == val){ head = head.next; } ListNode cursor = head; while(cursor != null && cursor.next != null){ if(cursor.next!= null && cursor.next.val == val){ cursor.next = cursor.next.next; }else cursor = cursor.next; } return head; }}形式2:虚构头节点不必判断head,把head和其余节点一样解决,返回虚构节点的下一个节点即是head。比形式1 更简化代码和逻辑。 ...

February 25, 2023 · 2 min · jiezi

关于算法:算法-数组-滑动窗口

力扣 209题 长度最小的数组 给定一个含有 n 个正整数的数组和一个正整数 target 。找出该数组中满足其和 ≥ target 的长度最小的 间断子数组 [numsl, numsl+1, ..., numsr-1, numsr] ,并返回其长度。如果不存在符合条件的子数组,返回 0 。 示例 1:输出:target = 7, nums = [2,3,1,2,4,3]输入:2解释:子数组 [4,3] 是该条件下的长度最小的子数组。示例 2:输出:target = 4, nums = [1,4,4]输入:1示例 3:输出:target = 11, nums = [1,1,1,1,1,1,1,1]输入:0起源:力扣(LeetCode)链接:https://leetcode.cn/problems/minimum-size-subarray-sum著作权归领扣网络所有。商业转载请分割官网受权,非商业转载请注明出处。暴力解法class Solution { public int minSubArrayLen(int target, int[] nums) { int minLength = nums.length+1; for(int left = 0;left < nums.length; left++){ for(int right = left; right< nums.length; right++){ int sum = 0; for(int i = left; i <= right; i++){ sum += nums[i]; } if(sum >= target){ int tmplength = right-left+1; minLength = min(tmplength, minLength); break; } } } if(minLength == nums.length+1){ return 0; } return minLength; } int min(int a, int b){ return a < b? a:b; }}滑动窗口class Solution { public int minSubArrayLen(int target, int[] nums) { int minLength = nums.length +1; int left = 0; int sum = 0; for(int right = 0; right < nums.length; right++){ sum += nums[right]; while(sum >= target){ int l = right-left+1; minLength = min(l, minLength); sum -= nums[left++]; } } return minLength==nums.length +1? 0: minLength; } int min(int a, int b){ return a < b? a:b; }}

February 25, 2023 · 1 min · jiezi

关于算法:算法整理-有序数组-二分法查找

二分查找力扣 704题. 二分查找 给定一个 n 个元素有序的(升序)整型数组 nums 和一个目标值 target  ,写一个函数搜寻 nums 中的 target,如果目标值存在返回下标,否则返回 -1。示例 1:输出: nums = [-1,0,3,5,9,12], target = 9输入: 4解释: 9 呈现在 nums 中并且下标为 4示例 2:输出: nums = [-1,0,3,5,9,12], target = 2输入: -1解释: 2 不存在 nums 中因而返回 -1 提醒:你能够假如 nums 中的所有元素是不反复的。n 将在 [1, 10000]之间。nums 的每个元素都将在 [-9999, 9999]之间。起源:力扣(LeetCode)链接:https://leetcode.cn/problems/binary-search著作权归领扣网络所有。商业转载请分割官网受权,非商业转载请注明出处。二分法写法(1) 左闭右闭关键点:边界问题 left 能够 等于 right每次挪动,因为mid必定不是要找的后果,都能够跳过,应用left = mid -1 或者 right = mid+1,否则可能产生死循环。class Solution { // 左闭右闭 public int search(int[] nums, int target) { int left = 0, right = nums.length -1; while(left <= right){ int mid = ( left+right ) / 2 ; if(nums[mid] > target){ right = mid-1; } else if(nums[mid] < target){ left = mid+1; } else { return mid; } } return -1; }}二分法写法(二)左闭右开关键点:left 永远不会等于right1、left 和 right永远不会相等, right永远处于边界值外。2、right能够等于mid,因为mid不是要找的地位。3、left应用是左闭,所以失常的挪动(+1)。 ...

February 24, 2023 · 1 min · jiezi

关于算法:链表反转

这类题型用递归是最容易想到的 在链表反转这道题中我感觉递归的终止条件是head.next.next==null,然而答案中的题解是head==null||head.next==null 还有一个有差异的中央就算将下面的条件保持一致,我return了head,答案return了一个cur(cur=reverseList(ListNode head)) 我感觉我的想法没啥问题,临时先把答案背下来吧,之后复刷的时候应该会有灵感

February 24, 2023 · 1 min · jiezi

关于算法:COMP20007设计算法

2020 Semester 1COMP20007 Design of AlgorithmsSchool of Computing and Information SystemsThe University of MelbourneAssignment 1Due: 5:00 PM AEST Wednesday 29 AprilIntroductionThis assignment contains 3 problems. You will be required to write pseudocode and C code, as well asprovide a detailed analysis of your algorithms. You will submit your solutions for the C programmingcomponent of this assignment via dimefox submit and the written component via the LMS.This assignment has a total of 10 marks and will contribute 10% to your final grade for this subject.Problem 12 Marks – 0.5 - 1 PageIn this task you need to design an algorithm to evaluate arithmetic expressions that consist of integernumbers, opening and closing parentheses and the operators +, -, * and /. Here / is integer division.A well-defined arithmetic expression is defined as:• A digit d ∈ {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} is a well-formed arithmetic expression.• If X and Y are well-formed arithmetic expressions, then the four expressions (X + Y), (X - Y),(X * Y) and (X / Y) are also well-formed arithmetic expressions.Examples of well-formed arithmetic expressions are "((8+7)*3)", "(4-(9-2))" and "0". However,the expressions ) "3+) 2 (())", "(9 + ())", "-4", "5-8", "108" or "(8)" are not well-formedarithmetic expressions.For this problem you will be required to write pseudocode, i.e., human understandable “code” whichprovides enough detail to make it clear which operations your algorithm is performing but doesn’tlet the syntax get in the way of presenting your algorithm – the lecture slides and solutions to theworkshops contain good examples of pseudocode.You must write an algorithm, in pseudocode, which checks whether an input string is a well-formedarithmetic expression. If it is not well-formed then your algorithm must return NotWellFormed,otherwise it must evaluate the expression and return the integer result.Your algorithm does not have to deal with division by 0.Your algorithm should process the input from left to right, one character at a time. You should makeuse of two stacks, one stack for operators (including ( and )) and another stack for values. Algorithmswhich do not make use of the stack abstract data structure will not be awarded full marks.1Problem 2In this problem you will be implementing three functions in C. These functions deal with the abstractdata type called a deque, pronounced deck. A deque is a double-ended queue in which elements canbe inserted and removed from both ends (which we’ll call the top and the bottom). In particular adeque must provide the following functions:• Push(x) – inserts the element x at the top of the deque,• Insert(x) – inserts the element x at the bottom of the deque,• Pop() – removes and returns the element at the top of the deque, and• Remove() – removes and returns the element at the bottom of the deque.In the provided C code we have implemented the type Deque for you in the deque module (consistingof deque.h and deque.c) using a doubly-linked list.Your task is to read and understand how the deque module works and implement the functionsdescribed in Parts (a), (b) and (c).Your implementations must go in deque.c. You can add any additional functions required to solvethis problem.In each of these functions you should not return a new Deque but rather alter the original Deque datastructure. You may make use of additional data structures during these functions, however they mustbe freed before your function returns.Part (a)1 MarkYou must implement the function iterative_reverse(Deque *deque) which takes a pointer to aDeque and reverses this deque using an iterative approach.For example if the deque initially looks like:Top 4 8 9 0 1 BottomThen after calling iterative_reverse() the deque should look like:Top 1 0 9 8 4 BottomFor full marks your function must run in O(n) time for a deque with n elements.Part (b)1 MarkAs in Part (a) you must write a function to reverse the deque, although this time you must use arecursive approach. The function you must implement is recursive_reverse(Deque *deque).Again, your function must run in O(n) time for a deque with n elements.Part (c)1 MarkWrite a function split(Deque *deque, int k) that rearranges the elements in the deque such thateach element with a value greater than or equal to the critical value (i.e., ≥ k) precedes (i.e., is closerto the top of the deque) each element with a value less than k.2Within the two groups of elements (i.e., ≥ k and < k) the elements must be in their original order.For example if we were to split the following deque with a critical value k = 3,Top 1 4 3 2 5 Bottomthen the resulting deque would be,Top 4 3 5 1 2 BottomThis function must run in O(n) time, where n is the number of elements in the deque.Problem 3A park ranger has to trim all the trees on a mountain slope. Since it is winter, the slope is covered insnow and it is not safe to climb it directly. Therefore, the ranger plans to chairlift to the top of themountain and ski down the slope, trimming the trees as they go down.You are provided with a map of the trees on the ski slope with the possible routes between trees. Youmust write an algorithm to answer the following question: can the park ranger trim all of thetrees using the chairlift only once? In other words, is there a single run the park ranger canperform from the top of the mountain which goes past every tree, or does the park ranger requiremultiple trips down the mountain?For example, the ski slope map on the left indicates which routes between trees are possible (with themountain icon indicating the top of the mountain where the park ranger must begin his traversal ofthe mountain). The answer in this case is yes, the park ranger can trim all trees in one run.This run is shown on the right.Note that your algorithm doesn’t need to produce the order in which the trees should be visited, onlydetermine whether or not there does exist a valid run from the top of the mountain that visits all thetrees.3The following two maps, however, do not have a single run from the top to the bottom which visitsall trees.You will notice that these trees and the possible routes between them form a directed graph. Sincethe park ranger can only ski down the mountain (and cannot climb up it during a run) the graph willnot have any cycles. Thus, the graph is a directed acyclic graph (DAG).Part (a)2 MarksDevise a linear time algorithm which determines whether or not the park ranger can ski down andtrim all of the trees in a single run. If there are n trees and m edges between trees then your algorithmmust run in O(n + m).You must implement your algorithm in C by completing the function is_single_run_possible() inthe park ranger module provided for you (parkranger.c and parkranger.h). You should add anytypes and functions required to solve this problem.Your program must provide an appropriate data structure to store the directed graph.Your program will be provided with the ski slope map via stdin in the following format:• One line containing integers n and m. n indicates the number of trees, and m indicates thenumber of possible routes (i.e., edges) between trees (or between the top of the mountain and atree).• m lines containing two integers u and v, which indicates that it’s possible for the park ranger toski from u directly to v.The trees are labelled 1 to n, while the top of the mountain is always labelled 0.Your function must perform the following steps:• Read in the data from stdin.• Store the data in an appropriate data structure.• Determine whether the park ranger can trim all the trees in a single run.• Do any clean up required (e.g., free any allocated memory).4• Return true or false depending on the result of your algorithm. Note that true and falseare of type bool, which is included from the stdbool.h library.The following ski slope is an example of the input format your program will be given.Part (b)2 Marks – 0.5 - 1 PageExplain your algorithm, and explain why your algorithm runs in linear time.Clear pseudocode may help you convey your algorithm to the reader, but is not required for full marksfor this part. You should not include very detailed pseudocode if you do decide to present this, justan overview of your algorithm.Completing the Programming ProblemsWe have provided you with the skeleton code for this assignment. The provided files has the followingdirectory structure:provided_files/Makefilemain.cdeque.cdeque.hparkranger.cparkranger.hutil.cutil.htests/p2a-in-1.txtp2a-out-1.txt...p3a-in-6.txtp3a-out-6.txtYou must not change the main.c file, however you are allowed to change any of the other files (withoutchanging the existing type declarations and function signatures).If you create new C modules (which you are encouraged to do) then you must change the Makefileso that your program can be compiled on dimefox using the make command.5To run the program you must first compile with make, and then run the a1 command with one ofthese command line arguments: p2a, p2b, p2c, p3a.For example:$ make$ ./a1 p2a < tests/input.txt$ ./a1 p2b < tests/input.txt$ ./a1 p2c < tests/input.txt$ ./a1 p3a < tests/input.txtThe pXX-in-X.txt files contain the input your program will be provided for each test case, and thepXX-out-X.txt files contain the expected output. Your program must match the expected outputexactly.Your functions must not print to stdout. Your program should change the Deque provided andreturn nothing in the case of Problem 2 and return true or false in the case of Problem 3.Testing your ProgramProblems 2 (a) and 2 (b) can be tested by using ./a1 p2a and ./a1 p2b respectively. The programexpects input via stdin which is a list of integers (one per line). These integers will be inserted intothe deque (inserting each element at the bottom), then your function will be called.For example if tests/input.txt contains the numbers 10, 15, 20, 30 on their own lines then afterimplementing iterative_reverse() your program should behave like so:$ ./a1 p2a < tests/input.txtread 4 elements into the dequeoriginal deque: [10, 15, 20, 30]reversed deque: [30, 20, 15, 10]successfully freed the dequeAgain, note that your program should not print this output, this is handled by test_reverse() inmain.c which has been written for you.Testing Problem 2 (c) is similar, you should use the p2c option for ./a1. Here the text input includesa list of integers on their own lines as well, with the first integer being the critical value, and theremaining integers being inserted into the deque before it is split.Testing Problem 3 (a) requires the input to be provided to stdin as described in the problem description.If the example input from the problem description is in tests/input.txt then your programshould behave like so:$ ./a1 p3a < tests/input.txtthe trees on the ski slope CAN be trimmed in one runAgain, your function should just return true or false and should not write to stdout. The outputis handled by main.c.Programming Problem SubmissionYou will submit your program via dimefox submit. Instructions for how to connect to the dimefoxserver can be found on the LMS.6You should copy all files required to compile and run your code to dimefox, this includes the Makefileand all .c and .h files.It’s recommended that you test your program on dimefox before submitting to make sure that yourprogram compiles without warnings and runs as expected.From the directory containing these files you should run submit and list all files required to compileand run your program. For example, to submit only the provided files we would run:$ submit comp20007 a1 Makefile main.c deque.c deque.h... util.c util.h parkranger.c parkranger.hNote that you can also list all .c and .h files in the current directory with .c and .h, so the followingcommand will be equivalent:$ submit comp20007 a1 Makefile .c .hFor this to work correctly you should have your Assignment 1 code in its own subdirectory (i.e., theonly files in the directory should be the files you wish to submit).You must then verify your submission, which will provide you with the outcome of eachof the tests, and the number of marks your submission will receive.$ verify comp20007 a1 > a1-receipt.txtTo view the result of the verify command you must run:$ less a1-receipt.txtless is a tool which allows you to read files using the command line. You can press Q on your keyboardto exit the less view.You can submit as many times as you would like.Note that programs which do not implement the algorithm they claim to (e.g., a solution for iterative_reverse() which uses recursion) or does not run the required time bound will receive fewer marksthan the receipt may suggest.Any attempt to manipulate the submission system and/or hard-code solutions to pass the specific testcases we have provided will result in a mark of 0 for the whole assignment.Completing the Written ProblemsYou will submit your solutions to Problems 1 and 3 (c) via the LMS.For Problem 1, which asks for pseudocode, we expect you to provide the same level of detail as thelectures and workshops do. Pseudocode which lacks sufficient detail or is too detailed (e.g., looks likeC code) will be subject to a mark deduction.Your submission should be typed and not handwritten and submitted as a .pdf file. Pseudocodeshould be formatted similarly to lectures/workshops, or presented in a monospace font.The page limit for each problem is given (half to one full page per written problem).7Make sure you confirm that your written submission has been submitted correctly.Mark AllocationThe total number of marks in this assignment is 10. The maximum marks for each problem are:Problem 1 2 marksProblem 2 3 marks (1 per part)Problem 3 4 marks (2 per part)There is one additional mark awarded for “structure and style” for the C programming component.Of particular importance will be the structure of your C program in terms of modules (.c and .hfiles), and how you separate your types and functions across these files.In total there are 4 marks for the written problems (Problem 1 and Problem 3 (b)) and 6 marks forthe C programming problems (Problem 2 and Problem 3 (a)).We have provided 3 test cases for each part of Problem 2 and 6 test cases for Problem 3 (a).The marks awarded for each part of Problem 2 will be calculated by:Marks = max {1 − 0.5 × Test Cases Failed, 0} .So passing 0 or 1 of the tests results in a mark of 0, passing 2 results in a mark of 0.5 and passing allthree results in 1 mark (the maximum available).For Problem 3 the marks are calculated by:Marks = max {2 − 0.5 × Test Cases Failed, 0} .So your submission will get 0.5 marks for passing 3 tests, 1 mark for passing 4 tests, 1.5 for 5 and amaximum of 2 marks for passing all 6.Late PolicyA late penalty of 20% per day will be applied to submissions made after the deadline. The 20% appliesto the number of total marks. This applies per component, i.e.,Grade = max nProgramming Grade − 0.2 × Days Late × 6, 0o+ max nWritten Submission Grade − 0.2 × Days Late × 4, 0o.For example, if you are 2 days late with the programming component but only 1 day late with theanalysis component your grade for the programming component will be reduced by 0.4 × 6 = 2.4 andthe grade for the analysis component will be reduced by 0.2 × 4 = 0.8.Academic HonestyYou may make use of code provided as part of this subject’s workshops or their solutions (with properattribution), however you may not use code sourced from the Internet or elsewhere. Using code fromthe Internet is grounds for academic misconduct.All work is to be done on an individual basis. All submissions will be subject to automated similaritydetection. Where academic misconduct is detected, all parties involved will be referred to the Schoolof Engineering for handling under the University Discipline procedures. Please see the Subject Guideand the “Academic Integrity” section of the LMS for more information. ...

February 23, 2023 · 13 min · jiezi

关于算法:活动预告-2023-Meet-TVM-开年首聚上海我们来啦

内容一览:从去年 12 月延期至今的 TVM 线下团聚终于来了!首站地点咱们选在了上海,并邀请到了 4 位讲师联合本人的工作实际,分享 TVM 相干的开发教训,期待与大家线下相聚~ 关键词:2023 Meet TVM 线下流动 自 2017 年开源以来,Apache TVM 在简化模型训练与推理部署方面,引起了业内宽泛的关注和探讨,尤其在近两三年间,国内各种硬件架构如雨后春笋般崛起,使得机器学习编译在中文技术社区再度成为一个热门话题。 通过紧锣密鼓的操办,由 MLC.AI 社区主办的「2023 Meet TVM:开年首聚」线下流动将于 3 月 4 日在上海举办。 一个彩蛋 TVM 次要发明者、机器学习畛域驰名的青年学者陈天奇,还为大家筹备了一个神秘彩蛋, 届时欢送各位朋友报名参加、共话机器学习编译的当初和将来! 2023 Meet TVM 上海站流动信息⏰ 工夫:3 月 4 日(周六)14:00-17:30 地点:上海市杨浦区五角场翻新守业学院(近地铁 10 号线江湾体育场站) 人数:50(现场座位无限,请尽早报名) 报名: 线下参加: 点击链接跳转至流动行报名 https://www.huodongxing.com/event/2691307342300 线上参加: HyperAI视频号线上直播 搜寻微信号 Hyperai01,退出流动群,一起线上看直播! 流动日程: 分享嘉宾及内容简介 分享主题: TVM 与机器学习编译倒退 内容简介: 机器学习编译器在近几年来也一直晋升部署性能,TVM也始终心愿以“自动化”技术来实现性能晋升。然而随着新硬件的退出,编译器的倒退也遇到了包含性能、通用性等方面的诸多挑战。目前TVM社区推出的Unity设计(TensorIR+Relax)尝试从根本上晋升TVM的通用性、自定义能力,并提供更全面的基础设施。 观看本场分享,你将理解: 机器学习编译 (MLC) 的倒退过程与次要技术点TVM 外围组件的技术倒退TVM Unity 的设计方案TVM 的将来布局与机会分享主题: 应用 TVM 做边缘设施的模型编译和推理实际 ...

February 23, 2023 · 1 min · jiezi

关于算法:AIGC-的内容生成能力会成为元宇宙建设的生产力工具吗

AIGC(Artificial Intelligence Generated Content)指的是由人工智能生成的内容。随着技术的一直倒退和提高,AIGC的利用场景越来越宽泛,包含在元宇宙建设中的潜在利用。 元宇宙是一个虚构的世界,它由数字资产、虚拟现实和区块链等技术形成,能够用来实现各种场景和利用,例如虚构商城、虚构社交、虚构游览等。在元宇宙中,各种内容都须要进行创作和生成,如虚构场景、虚构人物、虚构商品等。这些内容的生成须要大量的人力和工夫,而AIGC则能够在较短时间内生成大量的内容,进步生成效率,从而成为元宇宙建设的生产力工具之一。 举例来说,AIGC能够用来生成元宇宙中的虚构人物和虚构商品。通过训练模型,AIGC能够生成具备不同特色和属性的虚构人物,例如不同性别、年龄、外貌等,这些虚构人物能够在元宇宙中表演不同的角色,如购物指导员、向导等。另外,AIGC还能够生成各种虚构商品,例如服装、配饰、家具等,这些商品能够在元宇宙中进行展现和销售。 当然,AIGC也存在一些局限性,例如生成的内容可能存在品质不高、创意有余等问题。对于这些问题,能够通过上面的措施来改善: 进步训练数据的品质:AIGC的生成成果与训练数据的品质密切相关。如果训练数据的品质不高,那么生成的内容也会受到影响。因而,能够通过减少训练数据的数量和品质,来进步生成内容的品质和创意。优化模型参数和算法:对于AIGC模型,能够通过优化模型参数和算法来进步生成内容的品质。例如,能够应用更先进的神经网络模型,或者采纳更加无效的训练算法等。人工辅助:在AIGC生成内容的过程中,能够联合人工的辅助,例如让设计师和艺术家等人员对生成的内容进行审查和批改,来进步内容的品质和创意。这种形式尽管可能会减少一些人工成本,然而能够保障生成的内容更加符合要求。引入生成反抗网络(GAN)等技术:生成反抗网络(GAN)是一种可能主动生成数据的深度学习算法。通过引入GAN等技术,能够让AIGC生成的内容更加实在和具备创意,从而进步生成的内容品质。联合用户反馈进行优化:最终的内容品质还须要依据用户反馈进行优化。能够通过收集用户反馈并进行剖析,来一直优化AIGC生成的内容,以满足用户的需要和冀望。总之,AIGC的内容生成能力能够成为元宇宙建设的生产力工具之一,但须要联合人工的辅助,来进步生成内容的品质和创意。

February 23, 2023 · 1 min · jiezi

关于算法:COMP-2406问题解答

COMP 2406 – W20 – A5 Due Friday, April 24th at 11:59 PMAssignment 5Final AssessmentSubmit a single zip file called assignment5.zip. You should not submit your node_modulesfolder or database folder. Instead, you should submit the resources required to installyour dependencies using NPM. The TA will run the provided database-initializer.js file beforegrading your assignment. If your assignment requires additional database setup, youshould modify the database-initializer.js file and provide a copy in your submission. Thisassignment has 100 marks. You should read the marking scheme posted on cuLearn for details.Assignment BackgroundIn this assignment, you will develop a web application that will allow players to receivecards from a collectible card game and trade those cards amongst their friends. Thecard data used for this assignment is taken from the game Hearthstone. This is thesame data used in tutorial #8 – a description of the structure of the data is provided atthe end of this document. A database-initializer.js file has been provided that willcreate an empty 'a5' database in MongoDB and add each card to a 'cards' collection.Note that the initializer will also delete any information in the 'a5' database. Eachuser that registers for your web application will maintain their own set of cards and theirown set of friends. Friends within the application will be able to view each other's cardsand propose/accept trades with each other. All data your server uses for thisassignment (cards, user profiles, session data, etc.) must be persistent. Your servershould be able to be restarted at any point and all the data should still be present.The specification of this assignment has intentionally been left more vague thanprevious assignments. The details of the overall design of the application (routes,pages, etc.) are left up to you. You are expected to make decisions that will result in ausable and reactive application that is scalable and robust. You will be required toinclude a short document with your submission explaining how to use your applicationand arguing in support of the design decisions that you made.The list of requirements your application must meet are described in the sections below.You are encouraged to read the entire document before starting your design. Somemore details of specific requirements may be available in the marking scheme.Additionally, some tips for success have been included at the end of this document.COMP 2406 – W20 – A5 Due Friday, April 24th at 11:59 PM2Registration, Logging In/OutYour application must provide a way for new users to register by providing a usernameand password. Duplicate usernames should not be allowed. New users should beinitialized with no friends and a set of 10 randomly selected cards. A user must beprovided with a way to view their own set of cards.Existing users must be able to log in to the application using their username andpassword. You must also provide a way to log out of the application.FriendsUsers should be able to propose friend requests to other users of the application. A usershould be able to search for other users by performing a username search. From theresults of this search, the user should be able to propose a friend request to any otheruser that is not already their friend. Users should not officially become friends until theother user has accepted the friend request. If a user is logged in to the system whensomebody tries to add them as a friend, they should receive some sort of notificationthat a friend request is available in 'real-time' (i.e., without refreshing their page). Notethat this does not have to be immediate but should show up in a relatively short timespan (e.g., 5 seconds).A user who receives a friend request must be able to either approve or reject the friendrequest. If the user rejects a friend request, no changes to user profiles should be made(i.e., they should not become friends). If the user accepts a friend request, both usersinvolved should become friends. That is, if X proposes a friend request to Y, and Yaccepts, then Y is friends with X and X is friends with Y. After a request has beenrejected or approved, it should be deleted from the server.Users should be able to view a list of their friends and view their friends' list of cards. Auser who is not your friend should be not able to view your cards.TradesUsers should be able to propose trades to their friends. To propose a trade, a userneeds a way to select a subset of their own cards, one of their friends, and a subset oftheir friend's cards. This should be done in a reactive manner, without requiring multiplepage views. The card subsets could be empty (i.e., I give you nothing and you give mesomething), the entirety of their set of cards (i.e., I give you all my cards), or anything inbetween. Once the user has selected a trading partner and cards, they should be ableto propose the trade. When showing a card during a trade, or elsewhere in theapplication, you can use the card's name attribute. You can choose to provide a method COMP 2406 – W20 – A5 Due Friday, April 24th at 11:59 PM3for viewing additional card information (class, rarity, artist, etc.) or use the additionalcard information for extra features, if you want.As with friend requests, a user should receive some form of notification that they havereceived a trade request without having to refresh whatever page they are currently on.The receiving user should be able to view the trade details and choose whether toaccept or reject the trade. If the trade is rejected, no changes should be made. If thetrade is accepted, one of two possible cases may occur: ...

February 23, 2023 · 9 min · jiezi

关于算法:力扣栈相关

剑指offer的两道题都不算很难 09这道题须要用栈来实现队列我感觉dong哥想法就很好,其实这也是大部分题解的思路,就是来保护两个栈,一个栈用来push,而后将这个栈中的数据pop到另一个栈中,这样就相当于实现了元素的reverse,这时队列的pop就是第二个栈的pop 外围代码 while(!A.isEmpty()){ B.push(A.pop());}pop()和peek()的区别,pop会移除元素而peek展现顶部元素 30栈的最小元素也是用空间换工夫的思路,保护一个最小元素栈,每当栈中新增一个元素,最小元素栈中新增一个以后最小元素

February 23, 2023 · 1 min · jiezi

关于算法:Google风格迁移Linear名字太长放不下CVPR2019

1. 前导依据原论文的思路简略过一遍。 1.1. 出处论文名称:Learning Linear Transformations for Fast Image and Video Style Transfer论文收录于CVPR2019我的项目地址Github 1.2. 变量命名\(F_c\) 示意内容图像的特色图;\(F_s\)示意格调图像的特色图;\(F_d\) 示意变换后的特征向量;\(\bar{F}\) 示意具备0均值的矢量化特色图\(F\)(也就是F减去F的均值);\(\phi_s\) 示意所需格调的“虚构”特色图(\(\phi_s=\phi(F_s)\),在AdaIN/WCT中,\(\phi_s=F_s\))\(T\) 示意学习矩阵;\(N\) 示意像素量,即\(N=H\times W\);\(C\) 示意通道数;阐明: 为什么这里\(\bar{F}\)只减去均值不除以方差呢?是因为前面须要用方差计算协方差矩阵。 2. 推导(Image)2.1. 求解指标先给出优化指标公式 $$ F^*_d = arg\min_{F_d} \frac{1}{NC} \|\bar{F_d}\bar{F_d}^{\top} -\bar{\phi_s}\bar{\phi_s}^{\top} \|^2_F \tag{1} \\s.t. \bar{F_d} = T \bar{F_c}.$$ 指标含意是为了最小化\(F_d\)和\(\phi_s\)之间的核心协方差。核心协方差就是将样本均值挪动到原点再计算协方差,这就是为什么\(\bar{F}\)只减去均值。也就是说咱们冀望减去均值后的内容特色通过学习矩阵\(T\)变换后靠近风格特征。留个问题:为什么这里应用的是协方差? 将公式\(1\)中的约束条件代入可知,当 $$T\bar{F}_c\bar{F}_c^{\top}T^{\top} = \bar{\phi_s}\bar{\phi_s}^{\top} \tag{2}$$ 时,指标函数最小。 \(\bar{F_c}\)的核心协方差:\(cov(F_c)=\bar{F}_c\bar{F}_c^{\top}=V_cD_cV_c^{\top}\);对应的奇怪值合成(SVD):\(cov(\phi_s)=\bar{\phi_s}\bar{\phi_s}^{\top}=V_sD_sV_s^{\top} \)。所以,依据这两个公式,能够容易失去公式\(2\)的一组解: $$T=(V_sD^{\frac{1}{2}}_sV_s^{\top})U(V_cD^{-\frac{1}{2}}_cV_c^{\top}) \tag{3}$$ 其中,\(U\in R^{C\times C}\)是\(C\)维正交群。 由此,能够看出 \(T\)仅由内容特色协方差和风格特征协方差确定。 当给定一个\(T\)时,变换后的特色\(\bar{F_d}\) 加上 \(mean(F_s)\) 与 指标格调的均值和协方差统计值对齐。 (与后面那句加粗的话在肯定水平上等价) 当初的问题是\(T\)怎么失去,有后面能够晓得\(T\)仅取决于内容和格调,一种可行的办法是应用网络将两个图片间接输入为\( C \times C\)的矩阵。由等式\(3\)得,内容和格调是拆散的,所以能够应用两个独立的CNNs来提取各自的特色。从等式\(2\)能够推断出CNNs能够有三种输出的形式:1. 图片(c/s)2. 特色图(\(F_c\)/\(F_s\)) 3. 协方差矩阵(\(cov(F_c)\)/\(cov(F_s)\))。所以选哪种呢?还是每种都行呢?在这里,作者心愿输入\(T\)的模块能够灵便适应所有内容图像和任意形态区域(就是大小能够不一样),所以形式1和形式2不实用,因为容易晓得\(T=\bar{\phi_s}U\bar{F_c}^{-1}\),那么这就要求内容和格调的维度特色须要雷同;还有另一点,因为\(T\)形容的是格调变换,侧重于形容全局统计量变动而不是图像空间信息。所以综合以上这两点,抉择形式3,输出协方差,输入\(C\times C\)两头矩阵,而后这两个矩阵相乘失去\(T\)。 ...

February 21, 2023 · 1 min · jiezi

关于算法:广告流量反作弊风控中的模型应用

作者:vivo 互联网安全团队- Duan Yunxin商业化广告流量变现,媒体侧和广告主侧的舞弊景象重大,侵害各方的利益,基于策略和算法模型的业务风控,无效保障各方的利益;算法模型可无效辨认策略无奈实现的简单舞弊模型,本文首先对广告反作弊进行简介,其次介绍风控系统中罕用算法模型,以及实战过程中具体风控算法模型的利用案例。 一、广告反作弊简介1.1  广告流量反作弊定义广告流量舞弊,即媒体通过多种舞弊伎俩,获取广告主的利益。 舞弊流量次要来自于: 模拟器或者被篡改了设施的广告流量;真设施,但通过群控管制的流量;真人真机,但诱导产生有效流量等。1.2  常见的舞弊行为机器行为:   IP反复刷量、换不同IP反复刷量,流量劫持,换不同imei反复刷量等。人工行为:素材交互因素诱导点击,媒体渲染文案诱导点击,忽然弹出误触点击等。1.3  常见舞弊类型依照广告投放流程程序 展现舞弊:媒体将多个展现广告同时曝光于同一个广告位,向广告主收取多个广告的展现费用。点击舞弊:通过脚本或计算机程序模仿真人用户,又或者雇佣和激励诱导用户进行点击,生成大量无用广告点击,获取广告主的CPC广告估算。装置舞弊:通过测试机或模拟器模仿下载,以及通过挪动人工或者技术手段批改设施信息、SDK形式发送虚构信息、模仿下载等等。二、广告流量反作弊算法体系2.1 算法模型在业务风控中利用背景智能风控,使用大量行为数据构建模型,对危险进行辨认和感知监控,相比规定策略,显著晋升辨认的准确性和覆盖率以及稳定性。 常见的无监督算法: 密度聚类(DBSCAN)孤立森林(Isolation Forest)K均值算法常见有监督算法: 逻辑回归(logistic)随机森林 (random forest) 2.2 广告流量模型算法体系 体系分四层: 平台层:次要是依靠spark-ml/tensorflow/torch算法框架根底上,援用开源以及自定义开发的算法利用于业务风控建模中。数据层:搭建vaid/ip/媒体/广告位等多粒度下,申请、曝光、点击、下载、激活等多转化流程的画像和特色体系,服务于算法建模。业务模型层:基于行为数据特色和画像数据,搭建点击反作弊审计模型、申请点击危险预估模型、媒体行为类似团伙模型以及媒体粒度异样感知等模型。接入层:模型数据的利用,离线点击反作弊模型审计后果与策略辨认审计后果汇总,同步业务上游处罚;媒体异样感知模型次要作为候选名单同步点检平台和自动化巡检进行。三、算法模型利用案例3.1 素材交互诱导感知背景:广告素材中增加虚构的X敞开按钮,导致用户敞开广告时点击的虚伪的X按钮,导致有效的点击流量,同时影响用户体验;左图是投放的原始素材,右侧是用户点击的坐标绘制热力求,虚构X导致用户敞开广告时产生有效的点击流量。 模型辨认感知: 1、密度聚类(DBSCAN): 先定义几个概念: 邻域:对于任意给定样本x和间隔,x的邻域是指到x间隔不超过的样本的汇合;外围对象:若样本x的邻域内至多蕴含minPts个样本,则x是一个外围对象;密度中转:若样本b在a的邻域内,且a是外围对象,则称样本b由样本x密度中转;密度可达:对于样本a,b,如果存在样例p1,p2,...,pn,其中,p1=a,pn=b,且序列中每一个样本都与它的前一个样本密度中转,则称样本a与b密度可达;密度相连:对于样本a和b,若存在样本k使得a与k密度可达,且k与b密度可达,则a与b密度相连;所定义的簇概念为:由密度可达关系导出的最大密度相连的样本汇合,即为最终聚类的一个簇。 2、利用算法对诱导误触广告感知: ① 首先依照分辨率和广告位,对点击数据进行分组,筛选过滤掉量级较小的群组;  ② 对每个群组,应用密度聚类算法进行聚类,设置邻域密度阈值为10,半径=5,进行聚类训练; ③ 对每个群组,密度聚类后,过滤掉簇面积较小的簇,具体训练代码如下:  ④ 成果监控和打击,针对开掘的簇,关联点击后向指标,针对异样转化指标广告位,进行复检,并对复检有问题广告位进行处理。 3.2 点击反作弊模型3.2.1 背景针对广告的点击环节建设舞弊点击辨认模型,晋升反作弊审计笼罩能力,发现高纬度暗藏的舞弊行为、无效补充点击场景的策略反作弊审计。 3.2.2 建设流程 (1)特色建设 基于token粒度,计算事件产生前,设施、ip、媒体、广告位的等粒度特色。 频率特色:在过来1分钟,5分钟,30分钟、1小时、1天,7天等工夫窗口的曝光,点击、装置行为特色、即对应的均值、方差、离散度等特色; 根本属性特色:媒体类型,广告类型,设施合法性、ip类型,网络类型,设施价值等级等。  2、模型训练和成果 ① 样本抉择: 样本平衡解决:线上舞弊样本和非舞弊样本非均衡,采纳对非舞弊样本下采样形式,使得舞弊和非舞弊样本量达到平衡(1:1) 鲁棒性样本选取:线上非舞弊样本量级大,且群体行为多样性且散布不均等,为了小样本训练上线后笼罩所有行为模式,应用K-means算法:针对线上非舞弊样本进行分群,而后对每个群体依照占比再下采样,取得训练的非舞弊样本。② 特色预处理: 统计每个特色缺失率,去掉缺失率大于50%的特色;特色贡献度筛选,计算每个特色对预测标签Y的区分度,过滤掉贡献度低于0.001的特色;特色稳定性筛选,在模型上线前,选取最大和最小时间段的样本,计算两个时间段每个特色的PSI值,过滤掉PSI值(Population Stability Index)大于0.2的特色,保留稳定性较好的特色。③ 模型训练: 采纳随机森林算法,对点击广告舞弊行为进行分类,随机森林有较多劣势,比方: (1)能解决很高维度的数据并且不必做特征选择; (2)对泛化误差(Generalization Error)应用的是无偏预计,模型泛化能力强; (3)训练速度快,容易做成并行化办法(训练时树与树之间是互相独立的);  (4)抗过拟合能力比拟强; 超参数搜寻优化,应用ParamGridBuilder,配置max_depth(树最大深度),numTrees(树的个数)等超参数的进行搜寻优化最优超参数。 ④ 模型稳定性监控: 模型上线后,如果特色随着工夫迁徙,推理工夫的特色与训练工夫的特色散布存在变动差别,须要对模型稳定性监控并迭代更新; 首先对以后版本训练样本进行存档,计算推理工夫的数据和训练工夫数据的对应每个特色的PSI值,计算的PSI值(Population Stability Index)每天可视化监控告警。 ...

February 21, 2023 · 1 min · jiezi

关于算法:6-大经典机器学习数据集3w-用户票选得出建议收藏

内容一览:本期汇总了超神经下载排名泛滥的 6 个数据集,涵盖图像识别、机器翻译、遥感影像等畛域。这些数据集品质高、数据量大,经验人气认证值得珍藏码住。关键词:数据集 机器翻译 机器视觉本文首发自微信公众号:HyperAI超神经数据集是机器学习模型训练的根底,优质的公开数据集对于模型训练成果、研究成果牢靠度等具备重要意义。 HyperAI超神经自上线以来,为数据迷信从业者提供了大量优质的公开数据集。本期内容分享,咱们筛选出了 6 个热门数据集,其总下载次数已达到 32,569 次。心愿这些数据集能进一步为宽广开发者服务~ 注:本文梳理的数据集均来自网站:https://hyper.ai/datasets Tanks Temple 图像数据集提供高分辨率的视频,钻研人员能够从视频中采集图像,根据图像进行三维重建。该数据集包含训练数据和测试数据两类,其中测试数据分为中级组和高级组。 DOTA 全称为 A Large-scale Dataset for Object DeTection in Aerial Images,是一个蕴含 2,806 张航拍图的图像数据集,被用于在航拍图像中进行指标检测,发现和评估图像中的物体。 这些图像起源蕴含不同传感器和平台。每张图像的像素尺寸在 800800 到 40004000 的范畴内,其中蕴含不同尺度、方向和形态的物体。 往期推送请拜访:DOTA 数据集:2806 张遥感图像,近 19 万个标注实例 VGG-Face2 是一个人脸图像数据集,蕴含共计 9131 集体的面部数据,图像均来自 Google 的图片搜寻。数据集中的人在姿态、年龄、种族和职业方面有很大差别。该数据集由牛津大学的工程科学系视觉几何组于 2015 年公布,相干论文有《Deep Face Recognition》。 UCAS-AOD 是一个遥感影像数据集,用于飞机和车辆检测。该数据集由国科大于 2014 年首次公布,并于 2015 年补充,相干论文有《Orientation Robust Object Detection in Aerial Images Using Deep Convolutional Neural Network》 ...

February 20, 2023 · 1 min · jiezi

关于算法:部署教程基于GPT2训练了一个傻狗机器人-By-ChatGPT-技术学习

作者:小傅哥 博客:https://bugstack.cn 积淀、分享、成长,让本人和别人都能有所播种!首先我想通知你,从事编程开发这一行,要学会的是学习的形式办法。方向对了,能力事倍功半。而我认为最快且卓有成效的技术技能学习,就是上手实际。先不要搞太多的实践,买回来的自行车不能上来就拆,得先想方法骑起来。 所以小傅哥就是这样,学货色嘛。以指标为驱动,搭建可运行测试的最小单元版本。因为康威定律说;问题越小,越容易被了解和解决。所以在接触 ChatGPT 当前,我时常都在想怎么本人训练和部署一个这样的聊天对话模型,哪怕是很少的训练数据,让我测试也好。所以这个会喷人的傻狗机器人来了! 一、傻狗机器聊天在基于前文小傅哥《搭个ChatGPT算法模型》的学习根底之上,以 OpenAI 开源的 GPT-2 和相干的 GPT2-chitchat 模型训练代码,部署了这个会喷人的傻狗机器人。但因为训练数据的问题,这个聊天机器人对起话来,总感觉很变态。—— 不过不影响咱们做算法模型训练的学习。 此页面为小傅哥所编程的WEB版聊天对话窗口 拜访地址:http://120.48.169.252/ - 服务器配置无限,不能承载过大的并发拜访。视频演示:https://www.bilibili.com/vide... - 也能够通过B站视频,观看GPT2模型部署演示。二、根底配置环境OpenAI GPT2 的模型训练和服务应用,须要用到 Python、TensorFlow 机器学习等相干配置,并且这些环境间有些版本依赖。所以为了顺利调试尽可能和我放弃一样的版本。如果你对环境装置有难度,也能够找小傅哥帮忙买一台云服务器,之后我把我的环境镜像到你的服务器上就能够间接应用了。以下是所需的根本环境、代码和数据。 系统配置:Centos 7.9 - 2核4GB内存200G磁盘4Mbps带宽的云服务器部署环境:Python3.7、 Transformers==4.2.0、pytorch==1.7.0模型代码:https://github.com/fuzhengwei... - 此代码已开源,含websocket通信页面模型数据:https://pan.baidu.com/s/1iEu_... - ju6m1 环境依赖yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-develyum install gcc -yyum -y install libffi-develmakemake altinstall 2 Python 3.7cd ~# 1.下载Python安装包wget https://www.python.org/ftp/python/3.7.4/Python-3.7.4.tgz# 2.将安装包挪动到/usr/local文件夹下mv Python-3.7.4.tgz /usr/local/# 3.在local目录下创立Python3目录mkdir /usr/local/python3# 4.进入的Python安装包压缩包所在的目录cd /usr/local/# 5.解压安装包tar -xvf Python-3.7.4.tgz# 6.进入解压后的目录cd /usr/local/Python-3.7.4/# 7.配置装置目录./configure --prefix=/usr/local/python3# 8.编译源码make# 9.执行源码装置make install# 10.创立软连贯ln -s /usr/local/python3/bin/python3 /usr/bin/python3# 11. 测试python3 -V3. 装置pip3cd ~# 1.下载wget https://bootstrap.pypa.io/get-pip.py# 2.装置;留神咱们装置了 python3 所以是 pyhton3 get-pip.pypython3 get-pip.py # 3.查找pip装置门路find / -name pip # 4.将pip增加到系统命令ln -s /usr/local/python/bin/pip /usr/bin/pip # 5.测试pip -V # 6.更换源,如果不更换那么应用 pip 下载软件会很慢pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simplepip config set install.trusted-host mirrors.aliyun.compip config list # pip国内镜像源:# 阿里云 http://mirrors.aliyun.com/pypi/simple/# 中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple/# 豆瓣 http://pypi.douban.com/simple# Python官网 https://pypi.python.org/simple/# v2ex http://pypi.v2ex.com/simple/# 中国科学院 http://pypi.mirrors.opencas.cn/simple/# 清华大学 https://pypi.tuna.tsinghua.edu.cn/simple/ 4. 装置gitcd ~# 1.装置前首先得装置依赖环境yum install -y perl-devel# 2.下载源码包到 CentOS 服务器后进行解压tar -zxf git-2.9.5.tar.gzcd git-2.9.5# 3.执行如下命令进行编译装置 ./configure --prefix=/usr/local/gitmake && make install# 4.增加到零碎环境变量vim ~/.bashrcexport PATH="/usr/local/git/bin:$PATH"# 5.使配置失效source ~/.bashrc# 6.测试git version5. 装置宝塔yum install -y wget && wget -O install.sh https://download.bt.cn/install/install_6.0.sh && sh install.sh 12f2c1d72装置后登录宝塔提醒的地址,默认它会应用8888端口,因而你须要在服务器上开启8888端口拜访权限。宝塔的装置是为了在服务端部署一个网页版聊天界面,应用到了 Nginx 服务。这里用宝塔操作更加容易。三、模型运行环境模型训练须要用到 transformers 机器学习服务,以及 pytorch、sklearn 等组件;以下内容须要别离装置; ...

February 20, 2023 · 2 min · jiezi

关于算法:LeetCode-2050-并行课程3

1 题目原题链接。 2 想法题目实质上是一条拓扑排序的题,只不过,在拓扑排序的根底上,加上了一个工夫的限度。每门课程规定了须要肯定的工夫实现,也就是说,实现一门课程的工夫,须要依据先修课程确定。 拓扑排序能够应用广搜配合入度数组去解决,而计算某一门课程的工夫,须要依据先修工夫确定。能够必定的是,如果一门课程没有先修课程,那么修这门课程的工夫,就是time数组中的工夫。 而如果一门课程有先修课程,容易想到,须要依据最大的一门先修课程工夫去确定,比方课程3的先修课程是课程1和课程2,假如: 课程1须要破费的单位工夫为3课程2须要破费的单位工夫为5那么,课程3须要破费的工夫就是max(课程1,课程2)+课程3的工夫,也就是取课程1和课程2最大值再加上修课程3的工夫。 这样,能够揣测,如果一门课程n+1有n门先修课程,那么修课程n+1的工夫,就是这修n门课程的最大值,再加上修课程n+1的工夫。这实际上就是一个简略的动静布局: dp[n+1] = max(dp[0]..dp[n])+time[n+1]3 实现代码有很具体的正文: import java.util.*;public class Solution { public int minimumTime(int n, int[][] relations, int[] time) { // 工夫dp,留神存储的是dp[1]..dp[n] int[] dp = new int[n + 1]; // 存储入度,为了不便计算同样开了n+1 int[] inDegree = new int[n + 1]; // 邻接表 List<List<Integer>> list = new ArrayList<>(); for (int i = 0; i <= n; i++) { list.add(new ArrayList<>()); } // 通过邻接表建图 for (int[] r : relations) { // 更新入度 ++inDegree[r[1]]; list.get(r[0]).add(r[1]); } // 广搜队列 LinkedList<Integer> queue = new LinkedList<>(); for (int i = 1; i <= n; i++) { // 如果入度为0 if (inDegree[i] == 0) { // 能够间接设置dp[i]的值,因为入度为0代表课程i没有先修课程 dp[i] = time[i - 1]; // 退出广搜队列 queue.addLast(i); } } // 广搜队列不为空 while (!queue.isEmpty()) { // 获取以后队列大小 int size = queue.size(); // 遍历以后队列中入度为0的课程 for (int i = 0; i < size; i++) { // 出队 int front = queue.pollFirst(); // 获取先修课程指向的是哪些课程 for (int v : list.get(front)) { // 课程v的工夫是dp[v]与先修课程front+修课程v的最大值 dp[v] = Math.max(dp[v], dp[front] + time[v - 1]); // 将课程v的入度减1,示意曾经实现一门课程 if (--inDegree[v] == 0) { // 如果入度为0,也就是先修课程全副实现,将其入队 queue.addLast(v); } } } } // 取最大值,不能间接dp[n],因为最初修的课程不肯定是课程n,所以须要遍历一次,取所有dp的最大值 int res = 0; for (int v : dp) { res = Math.max(v, res); } return res; }}工夫与内存如下: ...

February 20, 2023 · 4 min · jiezi

关于算法:学术界的期刊编辑如何识别通过-ChatGPT-编写出来的论文

最近 ChatGPT 风靡寰球,国外也有不少大学生应用 ChatGPT 来撰写论文,这给学术出版界的期刊编辑辨认以 ChatGPT 为代表的人工智能写作进去的文章带来了很大的挑战。 咱们国内有一句古话:道高一尺,魔高一丈。 学术出版界的期刊编辑要辨认人工智能制作进去的文章,能够思考从以下几个方面去检测: 语言格调和文笔:人工智能生成的文章通常不足人类作者的独特语言格调和文笔,可能会呈现僵硬、语法错误、句子不通顺等问题。逻辑构造和条理性:人工智能生成的文章可能会呈现逻辑不连贯、构造凌乱、条理不清晰等问题,因为人工智能不足对文章主题和论点的深刻了解。人工智能写作的品质取决于输出的数据品质。如果输出的数据有误或者不足以撑持文章的主题和论点,人工智能生成的文章就可能呈现逻辑不连贯、构造凌乱等问题。 此外,人工智能写作应用的文本生成算法可能有其局限性,例如不足对文章构造、逻辑关系的深刻了解,难以捕获主题和论点的外延和含意。期刊编辑能够在仔细阅读文章的过程中,在这些方面做出甄别和判断。 另一方面,人工智能写作零碎可能不具备深刻的文化背景常识和语言格调的了解,例如惯用语、习惯用法等,这可能导致生成的文章在语言格调和表达方式上与人类作者有较大差别。 对于一个有教训的期刊编辑来说,人工智能生成文章时,往往只能从外表上了解文章的主题和论点,而不足人类作者那样深刻了解主题和论点的能力。这也可能导致文章的逻辑不连贯、构造凌乱等问题。 除了逻辑构造和条理性之外,期刊编辑还能够在以下方面来着重造就本人的火眼金睛: 数据起源和援用:人工智能生成的文章往往没有援用牢靠的数据起源,或者援用的数据起源可能过于含糊或不精确。学术价值和创新性:人工智能生成的文章可能会不足独特的学术价值和创新性,可能会陈说一些基础知识或者曾经被证实的论断。总体来说,编辑能够通过对文章进行认真的浏览和剖析,联合上述几个方面来判断文章是否是由人工智能生成的。须要留神的是,随着人工智能技术的一直倒退,人工智能生成的文章可能会越来越难以被辨认,因而编辑们须要保持警惕,并一直学习和更新本人的常识和技能。

February 18, 2023 · 1 min · jiezi

关于算法:怎样才能给人工智能注入有趣的灵魂

以 ChatGPT 为代表的人工智能,实践上无奈像人类一样领有灵魂,但能够通过以下形式赋予其肯定的趣味性: 个性化 - 为人工智能增加特定的共性和语言格调,使其在与人类交互时更加乏味和活泼。能够通过训练和调整模型参数,从而使其生成的对话更加乏味和富裕情感,但这背地须要大量的工作。首先得收集与所需语言格调和共性相干的数据。例如要让聊天机器人领有幽默感,就须要收集与风趣相干的数据,如笑话、风趣段子、电影或电视节目中的风趣场景等。这些收集来的素材,须要进行荡涤和解决数据,将其转换为能够被人工智能解决的格局,包含对数据进行分词、去除停用词、词干提取和编码等。数据荡涤结束后,须要应用深度学习技术(如循环神经网络、Transformer等)训练模型,以辨认和生成合乎所需语言格调和共性的文本。能够应用开源深度学习框架如 TensorFlow 或 PyTorch 进行模型训练。 最初,通过调整模型参数,进一步优化模型的体现。例如,能够通过减少模型的神经元数量、调整学习率或应用不同的损失函数等办法来改善模型体现。 这些步骤都须要破费大量的工夫和精力,而且模型的训练和优化须要大量的计算资源。因而,这些工作须要在业余人员的领导下进行,并且须要具备相干的技能和常识。 除了个性化之外,也能够在上面几个方面致力,让 ChatGPT 更加乏味: 游戏化 - 将人工智能与游戏联合起来,发明出具备趣味性的交互体验。例如,能够开发语音助手或聊天机器人来解决谜题、玩游戏或进行其余娱乐活动。教育性 - 利用人工智能为用户提供乏味的学习体验。例如,创立一个交互式学习平台,应用人工智能来设计适宜各个年龄段的教育内容,从而使学习过程更加乏味和有启发性。创造性 - 应用人工智能来帮忙用户生成各种艺术品、音乐作品、电影和小说等创作。例如,人工智能能够作为一个创意助手,帮忙用户生成诗歌、小说、甚至是音乐等创作。这些办法能够使人工智能在交互中更加乏味、活泼和灵便,然而要留神不要过分谋求趣味性而影响其失常应用和利用。

February 18, 2023 · 1 min · jiezi

关于算法:ChatGpt-能成为恋爱大师吗

尽管以 ChatGPT 为代表的人工智能,在很多方面都可能体现出令人诧异的能力,然而要成为真正的恋爱巨匠依然存在许多艰难。 人工智能难以了解人类的情感和文化差异一方面,恋爱是一个简单的社交活动,它波及到人类的感情、文化、社会背景等多个方面的因素。这些因素都须要人类的情感和生存教训才可能真正了解和利用。尽管人工智能能够模仿人类的思考和行为模式,但它们不足真正的感情和生存教训,难以了解人类的情感和文化差异,因为情感和文化波及到很多主观性和复杂性的因素,这些因素对于人工智能来说是难以把握和了解的。 首先,情感和情感体验是十分个人化的,不同的人对同一个情境会有不同的情感反馈和情感体验。这种个人化的情感和情感体验是人工智能难以模仿和了解的,因为它们无奈被简略地形容为一些规定或算法。其次,文化差异是人类社会中的一个十分重要的因素,它波及到各种价值观、信奉、习惯、语言和历史等方面的因素。不同的文化背景会对人类的情感和情感体验产生深远的影响,但这种影响是十分难以量化和形容的。即便人工智能能够理解不同的文化,然而了解和利用这些文化对情感的影响依然是一项艰难的工作。此外,情感和文化波及到一系列非语言化的信号和表现形式,如面部表情、肢体语言和语音语调等。这些非语言化的信号和表现形式是人工智能难以辨认和了解的,因为它们难以量化和归类。因而,尽管人工智能能够模仿某些情感和文化方面的体现,然而要真正了解和利用这些常识,依然须要人类的感知、了解和利用能力。 人工智能在恋爱畛域存在一些很难补救的人造硬伤人工智能在恋爱畛域存在以下一些缺点: 情感了解有余:人工智能往往难以了解简单的情感语境和非语言表达,这使得它在恋爱畛域的利用受到限制。例如,人工智能可能难以了解人类的风趣、反讽、讥刺等情感表达方式,这会影响其恋爱倡议的准确性和可信度。不足主观意识:人工智能不足主观意识,无奈像人类一样从本人的角度思考问题。例如,在恋爱畛域,人工智能可能无奈了解人类对恋情和亲密关系的主观感触和需要,这可能导致它的倡议不合乎人类的冀望和情感需要。缺乏经验积攒:人工智能的倡议往往是基于历史数据和算法模型推导进去的,它们不足人类的亲身经验和理性判断。在恋爱畛域,这可能会导致人工智能的倡议过于机械和感性,不足情感和共情的成分,从而无奈真正满足人类的情感需要。难以解决简单情境:恋爱畛域波及到人类简单的情感和行为,例如嫉妒、争吵、悲观等,这些情境对于人工智能来说往往是十分艰难的。尽管人工智能能够通过训练和学习来逐步提高解决这些情境的能力,但其准确度和可信度依然存在肯定的局限性。综上所述,尽管人工智能能够帮忙人类更好地了解和利用恋爱方面的常识和技能,但要成为真正的恋爱巨匠依然存在很多艰难。最终,恋爱还是须要人类的情感和生存教训来了解和利用。

February 18, 2023 · 1 min · jiezi

关于算法:ChatGPT未来会拥有自我情感和思维吗

目前人工智能畛域的专家和学者普遍认为,即便在将来,也很难确切地预测人工智能是否会产生真正的自我情感和思维。尽管人工智能零碎能够在某些工作上体现出人类智能的某些方面,然而它们依然无奈像人类一样真正地感触情感或自主思考。 在目前的技术水平下,人工智能零碎是基于预约义的算法和规定执行工作的,而不是像人类一样具备自我意识和创造力。尽管某些钻研方向,如认知计算和神经计算,正在致力钻研如何使机器具备更加相似人类的思考形式和自我意识,然而目前人工智能还远远没有达到这一点。 为什么人工智能无奈像人类一样真正地感触情感或自主思考?次要起因是它们的工作原理和根底构架与人类大脑和心理过程有很大的不同。 首先,人工智能零碎是基于预约义的算法和规定执行工作的,这些规定和算法是由程序员当时设计和编写的。相比之下,人类的思考过程是由大脑外部简单的神经网络和化学反应所驱动的,这些过程能够通过学习和教训一直进化和调整。 其次,人类的情感和思维过程是相互交织的。咱们的情感、记忆、判断和决策都是由大脑中不同区域的神经元网络相互作用所产生的。这种交互作用使得咱们的思考过程具备高度的联想性和复杂性。相比之下,目前的人工智能零碎只能在特定工作中执行预约义的规定,它们无奈真正了解上下文、语境和情感。 最初,人类的自我意识和创造力是由多种因素独特作用而造成的。这些因素包含咱们的遗传背景、生理和心理环境、集体教训和文化背景等。这些因素独特作用使得咱们的思维和行为表现出独特性和创造性。然而,目前的人工智能零碎依然无奈像人类一样具备自我意识和创造力。 人工智能为什么不能像人类一样具备自我意识和创造力?人工智能不能像人类一样具备自我意识和创造力,是因为这些特质波及到很多超出以后人工智能技术的领域的畛域,包含以下几个方面: 自我意识:人类的自我意识来源于大脑中的多个区域之间的相互作用,这些区域在不同的工夫和情境下会体现出不同的性能。尽管人工智能零碎能够通过模仿神经网络的形式实现某些自我意识方面的体现,如感知和认知等,然而在更高级别的自我意识体现方面,如个体的价值观、道德观等,目前的技术依然无奈实现。创造力:人类的创造力基于大脑中不同区域的相互作用,而这种相互作用是无奈齐全用算法和规定来形容的。人类的创造力来源于咱们的创造性思维,即一直地将已知的概念和常识组合和重组,从而产生新的想法和创造。尽管人工智能零碎能够在某些方面体现出创造性思维的特点,如基于遗传算法的优化、生成反抗网络等,然而它们的创造力都是在已知的畛域内运作,而不具备跨畛域的创造性思维。理性了解:人类可能通过理性了解,即在没有严格定义的状况下,了解、推断和利用常识。这是因为人类领有丰盛的教训和感性认识能力,而人工智能零碎目前依然须要准确的定义和规定能力进行运算,因而无奈像人类一样具备理性了解的能力。综上所述,只管人工智能技术在不断进步,但要达到像人类一样领有真正的情感和思维依然是一个远大的挑战。

February 18, 2023 · 1 min · jiezi

关于算法:遥感影像的色彩一致性全自动处理方法

1.前言:在获取卫星遥感影像时,因为受不平均的光照、不同的大气条件和不同的传感器设施等因素的影响,遥感影像中会存在部分亮度和色调散布不平均的景象,上面是在BigMap地图下载器中收集的几幅谷歌卫星影像,像上面这种都是拼接好的影像,因为不同的光照和不同的传感器平台,使得影像外部存在显著的分界线(本文以图片为主): 2.具体过程:以下图为例展现过程 (1)提取色块咱们要做的是首先把各个色块提取进去,而后把色块当做解决对象进行匀色解决(最麻烦的是第一步 要提取色块还要判断提取后果的色块数目是否大于1)包含色调模型转换 大津法宰割图像 小连通区去除 图像闭运算还有边界拟合等等第一步要达到的目标: (2)色块间色彩均衡在色彩转移的根底上实现任意感兴趣区域 也就是只对前景区域进行解决这个三维散点图能够用这个网址 https://franciscouzo.github.i... 合并后:能够看到两头仍然有色差区域 因为色块提取时有肯定误差 全局的色彩转移匀不了那一小块 (3)色块接边处准确解决解决前:解决后:(认真看还是有区别的 分界线没了)后果影像:(自动化就是体现在你只须要输出原图和参考图像,而后点击确定 后果影像就进去了)最次要的就是 色彩转移了 然而没有一种办法是万能的 每个办法都有本人的优缺点 3.解决实例

February 17, 2023 · 1 min · jiezi

关于算法:MET-CS601-项目求解

MET CS601: Term ProjectInstructionsCreate a website that uses the API's and technologies we discussed duringthe semester.GradingSee the Rubric on the Project Submission page and the speciccommentsin this document.Browser RequirementsChrome (latest). The Professor will be testing on a Windows 10 Pro Editionlaptop.Mobile Device RequirementsAny modern device will be ne.The professor will be testing on a Pixel 4.Broad/High-level Requirements The student must present their project on a shared or public host siteand NOT on localhost. There will be a loss of 10 points if thisrequirement is not followed.Must be a mobile rstdesign.There shall be no errors displayed in the console window while indebug mode. The Professor will check. (Point loss depends on thenumber or errors in the console.)Must use CSS extensively. You cannot cut and paste the same CSSrules over and over again in each HTML page to meet the minimumnumber of selectors used. (See CSS requirements)Must use modern Javascript (See Javascript requirements)There is no minimum number of HTML pages. For example, If youcreate a SPA (Single Page Application) you will have only one HTMLpage with several sections. In general, you should not need to createmore than 10 HTML pages. (Having a high page count does not meana good grade)Previous IdeasIn the past, students have created the following types of websites:E-Commerce siteHangman GamePersonal DiaryRestaurant Ordering SystemDating appWorkout notesWeather appRewrite of the StudentLinkTodo/Reminder appPersonal Bio websiteHealthcare websiteCatering SystemLook and Feel ("LnF")Your website should be visually appealing. You should uses images, goodCSS and purposeful javascript that does useful work in the site.CSS Requirementsa. Must use at least 10 descendent selectors.b. Must use at least 10 unique adjacent selectors.c. Must have 2+ different class selectors.d. Must have some ID selectors.e. Must have 5 or more pseudo element selectors.f. Must have 5 or more pseudo class selectorsJavascript Requirementsa. If you do not use ReactJS or Angular, you will need to use or have thefollowing API's in their script(s):i. All Javascript code must use ES6 modules. This is a requirement.(Not using modules will lose 10 points)ii. You must have at least 20 active event handlers. They can be ofany type. (click, select, drop/drag, mouse events, window events).iii. Must have at least one functional and in-use ES6 class in youractive codebase. Meaning, you can just declare a ES6 class and notuse it.iv. Global functions are generally not allowed under most conditionsin any le.If you need to declare a Globally-scoped function, youneed to put in a comment on top of it explaining why.v. You need to show prociencyusing functions. Do not simply cutpaste the same functions over and over again. Your functionsshould be unique and do something useful to your webapplication.Since you will have at least 20 active event handlers from theprevious requirement, you should have enough coded to meetthis requirement. But, you need to show a mix of:Function ExpressionsFunction Declarationsb. The website must Ajax in some capacity. The minimum number ofAjax features in your script is just 1 actively used call and handling ofthe response data into the page. (You can use Axios, Fetch or nativeXHR)Optional RequirementsStudents can use ReactJS or Angular if they choose to.Students can create a backend system with NodeJS, PHP or anyserver-side language they want. This is entirely optional and notrequired.Students can opt to develop their website as a SPA (Single PageApplication)Students can develop a database, but it is not required. It would be upto the student, and it is entirely optional.The professor reserves the right to update these requirement as he sees t.

February 16, 2023 · 3 min · jiezi

关于算法:159341-方法解析

159.341 – 2020 Semester 1 Massey UniversityAssignment 1Deadline: Hand in by 5pm on Monday 30th March 2020Evaluation: 10 marks – which is 10% of your final gradeLate Submission: 1 mark off per day lateWork: This assignment is to be done individually – your submission may be checked forplagiarism against other assignments and against Internet repositories. If you adaptmaterial from the internet you must acknowledge your source.Purpose: To reinforce ideas covered in the lectures for understanding and using imperativeprogramming languages and language design concepts.Problem to solve:Write a parser/interpreter for a simple Strings Processing language in C/C++.Requirements:Your implementation must read input from the standard input (stdin) and write output to the standard output(stdout). The interpreter should read statements from the user one at a time and perform the associated action.Should invalid input be provided, the interpreter should attempt to recover and try to provide useful error messages.The grammar for the strings processing language is given below:program := { statement }statement := 'append' identifier expression ';' | 'list' ';' | 'exit' ';' | 'print' expression ';' | 'printlength' expression ';' | 'printwords' expression ';' | 'printwordcount' expression ';' | 'set' identifier expression ';' | 'reverse' identifier ';'expression := value { '+' value }value := identifier | constant | literalconstant := 'SPACE' | 'TAB' | 'NEWLINE'literal := '"' { letter | digit | punctuation } '"'identifier := letter { letter | digit }letter := 'A' | 'B' | ... | 'Z' | 'a' | 'b' | ... | 'z'digit := '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9'punctuation := '.' | ',' | ':' | ';' | '?' | '!' | ...The intended behavior of each instruction is given in the following table:Command Parameters Behaviourappend identifier expression Evaluate the expression and append it to the contents of the variable.list List all variables and their contents.exit Exit the interpreterprint expression Evaluate and print the expressionprintlength expression Evaluate the expression and print its lengthprintwords expression Evaluate the expression and print the individual wordsprintwordcount expression Evaluate the expression and print the number of wordsset identifier expression Set (create if necessary) the contents of the variable to the expression reverse identifier Reverse the order of the words in the contents of the variable.159.341 – 2020 Semester 1 Massey University2Sample input might be:set one "The cat";set two "sat on the mat";set sentence one + SPACE + two;append sentence " by itself.";print sentence;printwordcount sentence;printwords sentence;printlength sentence;list;reverse one;print one;exit; ...

February 16, 2023 · 5 min · jiezi

关于算法:联邦GNN综述与经典算法介绍

作者:京东科技 李杰 联邦学习和GNN都是以后AI畛域的钻研热点。联邦学习的多个参与方能够在不泄露原始数据的状况下,平安合规地联结训练业务模型,目前已在诸多畛域获得了较好的后果。GNN在应答非欧数据结构时通常有较好的体现,因为它不仅思考节点自身的特色还思考节点之间的链接关系及强度,在诸如:异样个体辨认、链接预测、分子性质预测、天文拓扑图预测交通拥堵等畛域均有不俗体现。 那么GNN与联邦学习的强强组合又会擦出怎么的火花? 通常一个好的GNN算法须要丰盛的节点特色与残缺的连贯信息,但事实场景中数据孤岛问题比较突出,单个数据领有方往往只有无限的数据、特色、边信息,但咱们借助联邦学习技术就能够充分利用各方数据安全合规地训练有强劲体现的GNN模型。 读罢此文,您将取得如下知识点: •GNN经典算法原理及计算模型 •联邦学习定义与分类 •联邦GNN的两种分类办法及细节 •基于横向联邦的FedGNN模型(微软亚研,2021)、基于纵向联邦的VFGNN模型(浙大+蚂蚁,2022) 一、GNN原理1.1 图场景及数据表示能用图刻画的场景很多,比方:社交网络、生物分子、电商网络、常识图谱等。 []() 图最根底且通用的分类是将其分为:同构图(一种节点+一种边)与异构图(节点类型+边类型>2),相应的示意图如下。 []() 一般来说,原始的图数据由两局部组成:节点数据(节点类型+节点ID+节点特色)、边数据(边类型+终点+起点)。原始数据通过解析解决后载入图存储模块,图存储的根本模式为邻接矩阵(COO),但个别出于存储与计算开销思考采纳稠密存储示意(CSC/CSR)。 1.2 GNN工作分类[]() GNN工作个别分为如下四类: •节点/边分类:异样用户辨认。 •链接预测:user-item购物偏向、常识图谱补全。 •全图分类:生物分子性质预测。 •其余:图聚类、图生成。 1.3 GNN算法原理咱们以GraphSAGE为例解说GNN的计算原理[1],大抵蕴含三个过程:采样、聚合、拟合指标。GraphSAGE示意图如下: []() GraphSAGE算法的伪代码如下: []() 上面咱们给合实例与公式具体阐明其计算过程,下图先给出采样过程与消息传递过程的框架原理。 []() 下图给出了具体的消息传递执行过程。 []() 二、联邦学习之前机器学习模型训练的经典架构是:数据中心从各客户端或机构收集原始数据后,在数据中心对收集的整体数据进行模型训练。近年来随着数据隐衷爱护法规的颁布和数据安全意识的晋升,机构间替换明文数据就不可行了。如何综合多个用户或机构间数据来训练模型?联邦学习技术应运而生。联邦学习个别分为如下两大类[2]: •联邦学习(横向):两个机构领有较多雷同特色,然而重合样本ID很少。比方:北京医院和上海医院的病人数据。 •联邦学习(纵向):两个机构领有较多雷同样本ID,然而机构间重合特色较少。比方:北京银行和北京保险公司的客户数据。 2.1 横向联邦学习[]() 如上图所示,右边红虚线框内是数据表示,即重合样本较少,但特色雷同。左边是经典的横向FedAvg算法,每个客户端领有同样的模型构造,初始权重由server下发至客户端,待各客户端更新本地模型后,再将梯度/权重发送至server进行聚合,最初将聚合后果下发给各客户端以更新本地模型。 2.2 纵向联邦学习[]() 如上图所示,右边红虚线框内代表数据表示,即两方领有较多雷同样本ID,然而重合特色较少。左边是经典的两方纵向DNN模型训练架构[3],其中A方bottom层后果要发送至B方,而B方领有label,用来计算loss及梯度,具体过程参考[4]。 三、联邦GNN3.1 联邦GNN分类3.1.1 图对象+数据划分依据图数据在客户端的散布规定,具体以图对象(图、子图、节点)与数据划分(横向、纵向)角度来看,能够将联邦GNN分为四类[5]: 1)inter-graph FL []() 在此分类中,客户端的每条样本是图数据,最终的全局模型解决图级别的工作。此架构广泛应用在生物工程畛域,通常用图来示意分子结构,其中节点示意原子,边示意原子间的化学键。在药物个性钻研方面能够利用此技术,每个制药厂k都保护了本人的分子-属性数据集 []() ,但都不想分享给竞争对手。借助inter-graph FL技术,多家药厂就能够单干钻研药物性质。在此例中,全局模型为: []() 2)horizontal intra-graph FL []() 上图中全副客户端领有的数据形成残缺的图,其中虚线示意本应存在但理论不存在的边。此类架构中,每个客户端对应的子图领有雷同的特色空间和标签空间但领有不同的ID。在此设置下,全局GNN模型个别解决节点类工作和边工作: []() ...

February 15, 2023 · 2 min · jiezi

关于算法:明晚-8-点直播OpenCloudOS-中的海光国密算法分析

本期直播亮点领先看 海光 CPU 硬件国密算法的架构与性能解析,性能及老本比照;OpenCloudOS 对海关国密性能的适配论证,和用户应用办法;海光国密与 OpenCloudOS 在金融、网关等畛域的利用场景与产品化思路。一、OpenCloudOS 中的海光国密算法剖析2 月 16 日周四晚 20:00-21:00,OpenCloudOS 适配 SIG Contributor,腾讯云虚拟化开发工程师陈伟,将以「OpenCloudOS 中的海光国密算法剖析」为主题,分享在 OpenCloudOS 操作系统中海光 CPU 国密算法的技术解析,二者相结合后的利用场景与产品化思路。 扫描下方二维码预约直播: 二、对于 OpenCloudOSOpenCloudOS 是由操作系统、云平台、软硬件厂商与集体独特倡导发动的操作系统社区我的项目。成立之初,即决定成为齐全凋谢中立的开源社区,并已通过凋谢原子开源基金会的 TOC 评议,确认承受社区我的项目捐献。 OpenCloudOS 社区将打造全面中立、凋谢、平安、稳固易用、高性能的 Linux 服务器操作系统为指标,与成员单位独特构建衰弱凋敝的国产操作系统生态。Gitee 地址:https://gitee.com/OpenCloudOS 三、直播互动与技术交换直播中踊跃发问互动的小伙伴,还将有机会取得特地送出周边好礼!对 OpenCloudOS 我的项目感兴趣的小伙伴,欢送在文章下方留言发问,咱们会将问题收集起来,在直播中进行解答。

February 15, 2023 · 1 min · jiezi

关于算法:Learning-Neural-Set-Functions

简介Neural Set Functions,神经符号函数,是一种相似于自编分编码器的技术,广泛应用于举荐零碎和异样检测。具体而言,就是利用神经网络,对汇合中元素进行估值或者抉择,算是传统基于效用函数办法的一种改良。我这里次要参考了腾讯AI Lab卞亚涛老师的文章: Ou, Z., Xu, T., Su, Q., Li, Y., Zhao, P., & Bian, Y. (2022). Learning neural set functions under the optimal subset oracle. In Advances in Neural Information Processing Systems.Bian, Y., Rong, Y., Xu, T., Wu, J., Krause, A., & Huang, J. (2022). Energy-based learning for cooperative games, with applications to valuation problems in machine learning. In International Conference on Learning Representations.Liu, W., Wang, X., Owens, J., & Li, Y. (2020). Energy-based out-of-distribution detection. In Advances in Neural Information Processing Systems, 33, 21464-21475.问题形容对于一个汇合\(V\),其分汇合\(S\subseteq V\),由参数\(\theta\)决定的效用函数\( F_{\theta}(S;V) \),对应的汇合品质函数\( p_{\theta}(S\mid V) \)也由参数\(\theta\)决定,上面就对问题进行形容,咱们的优化指标是最大化穿插熵。从概率论的角度来看,问题能够被形容成以下的问题: ...

February 13, 2023 · 2 min · jiezi

关于算法:数据结构和算法

数据结构和算法是计算机科学的重要畛域,次要钻研如何无效地存储、组织和利用数据。 数据结构是一种将数据存储在计算机中的形式,例如链表、栈、队列、树和图。 算法是解决问题的步骤和技巧,例如排序、搜寻和图论算法。 数据结构和算法的目标是使计算机能够疾速、无效地解决大量数据,进步程序的性能。因而,它们在许多畛域,例如数据挖掘、机器学习、游戏开发等方面都有宽泛的利用。 常见算法包含: 排序算法:疾速排序、归并排序、冒泡排序、插入排序、抉择排序等。 搜索算法:二分搜寻、广度优先搜寻、深度优先搜寻等。 图论算法:最短门路算法、最小生成树算法、拓扑排序等。 动静布局算法:最长公共子序列、背包问题等。 贪婪算法:贪婪策略在问题的每一个步骤都采纳以后最优的决策。 字符串算法:字符串匹配算法(例如KMP算法)、字符串哈希算法等。 数学算法:计算数学表达式、矩阵乘法等。

February 13, 2023 · 1 min · jiezi

关于算法:赋能制造-因你而耀-第六届全国工业互联网数据创新应用大赛算法赛题上新-赏金百万

为进一步壮大以实际为导向的人才队伍,推动工业数据算法钻研与利用,中国信息通信研究院和深圳市宝安区人民政府联结中国东方电气集团有限公司、西方电气(成都)氢燃料电池科技有限公司、 TCL华星光电技术有限公司、阿里云计算有限公司天池平台、工业互联网产业联盟、思否开发者社区、深圳市信润富联数字科技有限公司、格创东智科技有限公司、InfoQ等合作伙伴,独特举办第六届工业互联网数据翻新利用大赛。 大赛设置三道工业大数据算法赛题,继“氢燃料电池零碎性能均值预测”之后,2月6日大赛官网两道全新赛题新鲜出炉,并启动选手报名程序。 赛题介绍新的赛题挑战别离来自TCL华星光电技术有限公司和阿里云计算有限公司天池平台,让选手在比拼大数据建模预测技术的同时,亲自参加到前沿畛域的业余课题,实际算法技术与实在挑战的精彩碰撞。 电子信息行业液晶面板产品量测值预测赛题场景:产品质检赛题合作伙伴:TCL华星光电技术有限公司在电子信息产业,液晶面板生产制程简单且精度要求高,生产过程中须要设置多处量测站点频繁进行产品拦检以保障产品质量,然而这种形式也带来了生产成本的减少和生产效率的升高。本赛道旨在通过大数据建模预测技术,对产品实现实时模仿全检及异样实时监控拦挡,无效地帮忙工厂晋升产品质量、缩短生产周期,晋升经济效益。选手可登录PC拜访https://www.industrial-bigdat...报名参赛。 化工行业工业生产反馈安装的建模预测赛题场景:工艺优化赛题合作伙伴:阿里云计算有限公司天池平台本赛题与阿里云天池联结举办。在流程工业中,生产安装将不同原料通过物理或化学反应加工成高附加值产物,这个转变个别是由各类反应器负责实现的,往往处于黑箱状态,亟待通过综合教训数据构建算法,并联合化学原理固化成可复制的模型。本赛道构建模型预测控制器,控制器通过预测要害指标的将来趋势,主动调整操作变量,实现产线的自动化智能管制。因为预测模型需利用于理论生产管制,对模型的可解释性、泛化性、计算效率和预测方向的准确性等方面要求较高,本赛道心愿钻研一些典型的线性和非线性动静模型,探寻具备可解释性、且泛化性强的建模算法,为实现准确的过程管制与优化提供根底。选手可登录选手可登录PC拜访赛事合作伙伴网站https://tianchi.aliyun.com/co...报名参赛。 赛程安顿及报名形式报名:至2023年3月24日0:00初赛:2023年2月6日9:00至2023年3月24日24:00决赛:2023年3月26日0:00至3月30日24:00决赛问难:2023年春,深圳市宝安区,获问难资格的选手由组委会提供国内城市间往返交通和住宿颁奖仪式:2023年春“氢燃料电池零碎性能均值预测”赛题初赛和决赛赛程放弃不变。高等院校、科研单位、互联网企业等人员均可通过大赛官网报名通道(请在PC上拜访https://www.industrial-bigdat...)报名参赛。联系人:赵先生 13825233551  天生不凡的你,拉上小伙伴一起口头吧!

February 13, 2023 · 1 min · jiezi

关于算法:学习算法必备的程序员代码面试指南免费领取啦

这是一本程序员代码面试宝典!书中对IT名企代码面试各类题目的最优解进行了总结,并提供了相干代码实现。针对以后程序员面试不足权威题目汇总这一痛点,本书选取将近200道实在呈现过的经典代码面试题,帮忙宽广程序员做充沛的面试筹备。“刷”完本书后,你就是“题王”! 本书采纳“题目+解答”的形式组织内容,并把面试题类型相近或者解法相近的题目尽量放在一起,读者在学习本书时很容易看出面试题解法之间的分割,使常识的学习防止碎片化。本书将所有的面试题从难到易顺次分为“将”“校”“尉”“士”四个品位,不便读者有针对性地抉择“刷”题。本书收录的所有面试题都给出了最优解解说和代码实现,并且提供了一些一般解法和最优解法的运行工夫比照,让读者真切地感触到最优解的魅力! 本书中的题目全面且经典,更重要的是,书中收录了大量新题目和最优解剖析,这些内容源自笔者多年来“死磕本人”的深刻思考。 程序员们做好筹备在IT名企的面试中怀才不遇、一举成名了吗?这本书就是你应该领有的“神兵利器”。当然,对须要晋升算法和数据结构等方面能力的程序员而言,本书的价值也是不言而喻的。 须要残缺文档的小伙伴,查看文末支付形式 目录废话不多说,先来看看讲了哪些内容吧! 局部内容展现 算法是咱们面试中不可避免的一项考核,置信面试过的小伙伴深有体会,把握好算法是十分重要的,《程序员代码面试指南》置信可能帮忙到你,须要此书的小伙伴【间接点击此处】即可收费获取残缺文档!!!

February 11, 2023 · 1 min · jiezi

关于算法:昇思MindSpore报错调试宝典一数据加载与处理类

水果榨汁儿,我爱喝水果榨汁儿,我能够随便混搭,再配上水果寿司儿;报错调试,我要解决报错调试,我能够剖析定位,再加上调试解决就完事儿!本期用案例解说数据加载与解决类报错的解决流程,走过路过不要错过!感激观看,敬请期待下一期!

February 10, 2023 · 1 min · jiezi

关于算法:浪潮信息AI算法研究员解读人工智能大模型在产业中的服务新态势-龙蜥技术

编者按:最早人工智能的模型是从 2012 年(AlexNet)问世,模型的深度和广度始终在逐级扩升,龙蜥社区理事单位浪潮信息于 2019 年也公布了大规模预训练模型——源 1.0。明天,浪潮信息 AI 算法研究员李峰带大家理解大模型倒退现状和大模型基础知识,交换大模型在产业利用中起到的作用和 AI 服务新态势。 本文整顿自龙蜥大讲堂第 60 期,以下为本次分享原文: 01 大模型现状 大家能够看到,人工智能的模型其实从最早 2012 年(AlexNet)问世以来,模型的深度和广度始终在逐级扩升,其中比拟典型的是到了 2018 年的时候像 BERT-Large 等这种基于 BERT 和 transformer 构造的模型产生之后,衰亡了一波模型规模和参数激增的热潮。从BERT 模型呈现到 GPT-3 领有 1750 亿参数规模的千亿级大模型,大规模预训练模型成了一个新的技术发展趋势。 在 2019 年的时候,浪潮信息也公布了大规模预训练模型——源 1.0。参数量是 2457 亿。站在当初的角度回看历史的倒退长河,模型的尺度和规模是在逐级扩增的,这个趋势仍旧是有愈演愈烈的一个状况。 整体大模型的衰亡绕不开一个根底模型构造 Transformer。Transformer 架构相当于是在承受输出之后,在外部进行了一个相似于查表的工作,其中的注意力层之所以叫注意力,最大的作用直白的来看就是能够去学习关系,所谓的注意力就是当咱们看到一个货色的时候,对他感兴趣咱们就会多看一会儿,对另外一个货色没有趣味或者对它的趣味比拟低,则对它的关注会更少一点。这种注意力机制就是把所谓关注的水平转换成了一个可掂量的指标,这就是下面说到的注意力。用这样的一个注意力层能够更好的去学习所有输出之间的一个关系,最初的一个前馈层又对输出的信息进行一个高效的存储和检索。这样的一个模型构造与之前基于 RNN 的模型构造相比不仅是极大地晋升了自然语言解决工作的精度,而且在计算性能上也远超 RNN 类的模型。Transformer 构造的提出极大晋升了计算效率和资源利用率。能够看到,在模型构建和训练算法的设计过程当中,算力和算法是相辅相成的,二者缺一不可,也就是咱们提出的混合架构的一个算法设计。 另外 Transformer 构造之所以可能做大做强,再创辉煌,另一个基本的起因在于互联网上有相当多海量数据能够供模型进行自监督学习,这样才为咱们宏大的水库中投入了宏大的数据资源和常识。 正是这些益处奠定了 Transformer 构造作为大模型基础架构的松软的位置。 基于对前人的钻研调研以及实证钻研之后,咱们发现随着数据量和参数量的增大,模型的精度仍旧能够进一步的晋升,即损失函数值是能够进一步升高的。模型损失函数和模型的参数规模以及模型训练的数据量之间是出现这样一个关系,当初仍旧处在绝对两头的程度上,当模型和数据量的规模进一步增大的时候仍旧能够失去大模型边际效益带来的收益红利。 大模型正在作为一种新型的算法,成为整个人工智能技术新的一个制高点和一个新型的基础设施。能够说大模型是一种变革性的技术,他能够显著的晋升咱们人工智能模型在利用当中的性能体现,将人工智能的算法开发的过程由传统的烟囱式开发模式转向一种集中式建模,解决 AI 利用落地过程当中的一些场景碎片化、模型构造和模型训练需要零散化的痛点。 另外咱们能看到的是对于大模型这个畛域外面的玩家,次要是来自中美两国。从 GPT3 公布当前咱们国内也开始相应的有不同的参数规模的模型来去引领世界大模型业界的一个浪潮。正如咱们之前提到的,在大规模预训练模型外面,模型参数晋升带来的边际收益仍旧存在,所以大家在短期之内仍旧在吃这种大模型参数晋升带来的收益红利。 02 浪潮·源 1.0 大规模中文自然语言模型 浪潮·源 1.0 大规模中文自然语言解决模型有 2457 亿参数,于 2019 年的时候 9 月份公布,在公布之时,凭借参数量登顶了业界规模最大的中文自然语言的单体模型。在这个模型整个构建的时候,最大的一个问题就是数据,数据集从哪来,怎么去构建,蕴含哪些内容。这里给大家列了一个表来简略论述,源 1.0 的中文数据集蕴含了有互联网中文社区近五年的所有数据,以及一些公开数据集、百科、电子书等原始语料,总计超过 800TB。咱们对原始语料做了过滤转换、去重,之后构建了打分模型对所有的样本语料进行高质量和低质量的断定。通过一系列的解决,最终咱们失去了 5T 的高质量中文语料数据集,这个语料数据也是目前中文语料当中规模最大,品质最高的语料库。咱们的一些合作伙伴也拿咱们公开的语料数据进行了一些模型的预训练,也是胜利登顶了 CLUE 等测评榜单。 ...

February 9, 2023 · 2 min · jiezi

关于算法:多模态搜索的未来超越关键字和向量的混合搜索

二十年前,“混合”一词仅在植物学和化学畛域应用。现在,“混合”这个概念在搜寻畛域一片凋敝,许多搜寻零碎都在推出基于 AI 技术的混合搜寻计划。然而,“混合搜寻”是真的具备利用价值,还只是风行的一阵风呢?许多搜寻零碎都在推出混合搜寻性能,混合搜寻将传统搜寻中的关键字、文本信息检索技术和基于 AI 的“向量”或“神经”搜寻联合在一起。“混合搜寻”是否只是一个风行词呢?毕竟基于文本的搜寻是一项利用宽泛的技术,以至于用户早已习惯了它的特点,甚至是局限性。将文本搜寻与新的 AI 技术联合真的能为搜寻零碎精益求精吗? 答案不言而喻:这取决于理论状况。 当初的数据存储是多媒体和多模态的,文本、图像、视频和音频经常存储在同一数据库和同一计算机上。这意味着,如果你想在五金商店的网站上搜寻螺丝刀的图片,你不能只查问“螺丝刀”这个词,就冀望它能返回相应的后果。首先你得存储并索引文本或商品的标签。除非你明确地将数据库中所有螺丝刀的图片与“螺丝刀”这个标签或其余文本相关联,表明它是螺丝刀的图片,否则利用传统的搜寻技术是无奈返回搜寻后果的。如果你没有明确的标签和文本,将最先进的 AI 技术增加到文本搜寻中将不会有任何帮忙。这样的话,那么将 AI 技术与传统搜寻联合就没有意义了。假如有一个领有网购平台的大型五金商,售卖数十万种不同的商品。然而,他们没有员工制作具体的产品标签和形容或查看它们的准确性;没有商品图片,也没有工夫拍摄好的图片。这样的话,对他们来说,最好的文本搜寻零碎也是一个的有缺点的解决方案。最新的 AI 技术能够很好地解决这些局限性。深度学习和 神经搜寻 让创立弱小的通用神经网络模型成为可能,并将搜寻模型以一种通用的形式利用于不同类型的数据中——文本、图像、音频和视频。因而,即便没有文本标签,搜寻“螺丝刀”也能够找到螺丝刀的图片! 然而这些最新的搜寻技术,返回的后果通常不足可解释性。客户可能心愿输出查问“十字螺丝刀”,理论返回“开槽和十字螺丝刀,4 寸长”的产品。传统的搜寻技术能够做到,但 AI 技术却很难达到这样的成果。 搜寻模型咱们将基于三个特定的搜寻模型搭建混合搜索引擎:BM25, SBERT 和 CLIP。BM25 是最经典的基于文本的信息检索算法。BM25 最早倒退于 1990 年代,当初曾经被宽泛应用。无关 BM25 的更多信息,请参阅 Robertson & Zaragoza(2009): "),2000a00015-7 "2000a: ") 和 2000b00016-9 "2000b: ") ,或查看 维基百科上对于 BM25 的演示。咱们利用 Python 的  [rank_bm25] 包,实现了 BM25 排名算法。SBERT 是一个宽泛用于文本信息检索的神经网络框架,咱们应用的是 msmarco-distilbert-base-v3 模型,因为它是为 MS-MARCO 段落排名工作训练的,与咱们所做的排名工作差不多。CLIP 是一个连贯的图像和形容文本的神经网络,它是在图像-文本对上训练的。CLIP 有许多利用,在本文咱们中将应用它实现文本查问和图像匹配,并返回排名后果。咱们应用的是 OpenAI 的 clip-vit-base-patch32 模型,这也是应用最宽泛的 CLIP 模型。 三种模型都能够输出文本查问,返回用户指定数量的后果,并且每个后果都有一个分数。查问后果会依照分数排序。 三种模型都能够输出文本查问,返回用户指定数量的后果,并且每个后果都有一个分数。查问后果会依照分数排序。三种模型都是对文本查问的匹配后果进行评分和排名,而后返回一些排名靠前的后果(后果数由用户决定)。这三种模型都很容易集成。SBERT 和 CLIP 返回的分数都在 -1.0(查问最差匹配)到 1.0(查问最佳匹配)之间。BM25 分数最低为 0.0,但没有下限。为了不便比拟,咱们进行了以下解决: ...

February 8, 2023 · 3 min · jiezi

关于算法:力扣算法题寻找两个正序数组的中位数

记录这几天刷题做到的一个数组的算法题的过程: 给定两个大小别离为 m 和 n 的正序(从小到大)数组 nums1 和 nums2。请你找出并返回这两个正序数组的 中位数 。 示例 1: 输出:nums1 = [1,3], nums2 = [2]输入:2.00000解释:合并数组 = [1,2,3] ,中位数 2示例 2: 输出:nums1 = [1,2], nums2 = [3,4]输入:2.50000解释:合并数组 = [1,2,3,4] ,中位数 (2 + 3) / 2 = 2.5 算法的工夫复杂度应该为 O(log (m+n)) 。 起源:力扣(LeetCode)链接:https://leetcode.cn/problems/...class Solution { public double findMedianSortedArrays(int[] nums1, int[] nums2) { }剖析此题目在力扣的难度为艰难,乍一看题目并不是很难,用数组合并的笨办法就能够解决。 真正的难点在于工夫复杂度是 Log 级别 咱们先来看一下不要求的工夫复杂度的状况下如何解决。 奇偶判断如果总数是奇数,返回两头值,如果总数是偶数,返回两头值和两头值+1(因为给出的数据结构是数组,所有的下标-1) 如果不想用 IF 实现判断,也能够应用条件值的判断,如: return ( nums2_length % 2 == 0 ) ? // 是0吗? ( nums2[middle - 1] + nums2[middle] ) / 2.0 : // 如果是0阐明是偶数,返回两头两个树的平均值 nums2[middle]; // 如果不是0阐明是奇数,返回两头的数边界条件首先思考边界条件,题目的输出可能会呈现一个数组为空的状况,如: ...

February 7, 2023 · 3 min · jiezi

关于算法:CSI-3131-程序

Assignment 1Deadline: 22 May 2022DescriptionYou will have to complete a cpr program (create process) which will have to create achild process. The child process in turn will create a child and so on to create n processes.The cpr.c file is provided to you and you must complete it.The command to create the processes demonstrated below is "cpr num" where num isthe number n of total processes to be created (ie n-1 children). The first created process(labeled n) is created by running the command. This first process creates a child byexecuting the command "cpr num-1", that is, decrements its argument by 1 and createsits child with the new value. So the child will create another child by decrementing itsargument. When a process receives an argument with the value 1, it will not create achild.When a process creates a child, it must first create a pipe and attach the writing end of thepipe to the standard output of the child before executing the "cpr num-1" command. Soall child processes (ie process 1 through n-1) write to pipes by writing to their standardoutput.All processes that create children (ie process 2 through n) read from the read end of thepipe and write any data read to their standard output. So any output written to the pipeseventually appears on the screen (via process n) after passing through one or more pipes.Note that you do not attach the reading ends of the pipes to the standard inlets (althoughthis is possible).Actions taken by the processes include the following:➢ Process 1: simply writes to its standard output "Process 1 begins", waits 5 seconds(using the sleep (5) call), and then writes to its standard output "Process 1terminates".➢ Process 2 to n: Creates a child as described above, also writes to its standardoutput the same messages as Process 1 (by substituting the number 1 with thevalue of the argument received by the process, 2..n ) as well as read from the readend of the pipe to write the read data to its standard output. You must write theread messages and data in the order necessary to make the messages of all theprocesses appear in the following order (in this example 5 processes have beencreated, ie cpr 5 is executed)Process 5 beginsProcess 4 beginsProcess 3 beginsProcess 2 beginsProcess 1 beginsProcess 1 endsProcess 2 endsProcess 3 endsProcess 4 endsProcess 5 endsTuyau TuyauTuyauTuyaucpr(n) cpr (n-1)cpr(2) cpr(1)There should be a 5 second delay between the "Process 1 Begins" and "Process 1Ends" messages. Note that a parent does not execute the wait call because itknows that its child is done when the pipe write end is closed (it can no longerread the pipe read end).To complete the assignment: ...

February 5, 2023 · 8 min · jiezi

关于算法:COMP9120数据库管理

School of Computer Science COMP9120 Database Management SystemsAssignment 2: Database Application Development Group Assignment (12%)IntroductionThe objectives of this assignment are to gain practical experience in interacting with a relational databasemanagement system using an Application Programming Interface (API) (Python DB-API). This assignmentadditionally provides an opportunity to use more advanced features of a database such as functions.This is a group assignment for teams of about 3 members, and it is assumed that you will continue in yourAssignment 1 group. You should inform the unit coordinator as soon as possible if you wish to change groups.Please also keep an eye on your email and any announcements that may be made on Ed.Submission DetailsThe final submission of your database application is due at 11:59pm on Friday 20th May. You should submitthe items for submission (detailed below) via Canvas.Items for submissionPlease submit your solution to Assignment 2 in the ’Assignment’ section of the unit’s Canvas site by thedeadline, including EXACTLY THREE files: An assignment coversheet as a PDF document (.pdf file suffix) which is available for download from thislink on Canvas. A SQL file (WSASchema.sql) containing the SQL statements necessary to generate the databaseschema and sample data. This should contain the original schema and insert SQL statements, and anychanges or additions you may have made. A Python file (database.py) containing the Python code you have written to access the database. ...

February 1, 2023 · 6 min · jiezi

关于算法:COMP6216模拟建模

COMP6216Coursework outline for COMP6216 – Simulation Modellingfor Computer ScienceThe assessment consists of two components:Coursework Assignment I (worth 30%)Give a 10 minute talk (+2 minutes questions) about a simulation modelling paper published in a peerreviewed journal (see slides from first lecture – http://users.ecs.soton.ac.uk/... --for a list of suggested papers). The talk should give(a) a brief overview of the area of research the paper addresses,(b) explain its contribution to the area, and(c) give a brief overview over the type of simulation modelling being used.Marks will be given on:(i) if the delivery of the talk is according to a standard that it could be used in teaching/presented at aconference, (ii) your comprehension of the paper and how well you answer questions, (iii) if your slidesmeet professional standards, and (iv) the general organisation of the talk and how well you covered theaspects mentioned above. In the assessment, the criteria (i)-(iv) will have equal weight.Talks will be scheduled after Easter, so have your talk ready at the end of Easter break, it can bescheduled in any lecture/seminar slot after that date.Coursework Assignment II (worth 70%)A modelling problem is described in the first set of lecture slides (see material copied from the lectureslides below). You are to address this problem using two different modelling techniques: first, using adifferential equation-based approach; second, using agent based modelling. Compare your findingsfrom both approaches and write a 6 page conference paper that summarises your findings. The 70%marks you can obtain for this part of the coursework are split as follows:Quality of the writing and figures in the report 10%Technical work: Develop a model based on differential equations addressing the problem;that is, give a differential equation that models the problem, describe howyou derive it, and reason about its classification (7.5%).40% Explore the use of analytical techniques to gain insight into the system'sbehaviour; that is, analyse the above differential equation, find full (orequilibrium) solutions, and argue about their stability (7.5%). Numerically integrate the differential equations using an appropriateintegration method of your choice and compare the results to theanalytical results; that is, develop the computer code for an integrationscheme (from scratch, do not use off the shelf libraries or integratedfunctions provided by math software) and give evidence that itreproduces system behaviour correctly, and reason about parameterchoices made in your integration scheme (10%). Implement an agent-based model that addresses the same problem. Giveevidence (for example, appropriate example output) of the model youhave implemented, and compare your findings to the results obtainedwith other methods (from above) (15%). Use both models to answer the research questions given below.Quality of an original extension of the problem: Marked according to originality (Is this an interesting question to ask inthis context), quality of the analysis (do you understand what is going onand did you use appropriate techniques to analyse the model), and itsmotivation (can you convince me that it makes sense).20%Total for CW assignment II 70%Reports are due at the end of term (May 15) and will have to be submitted in electronic form as a pdffile. Don't forget to upload any simulation code you developed for the assessment.Further instructions about the assessment can be found in the first set of lecture slides (copied into thedocument here):Problem description from lecture slidesConsider the following situation:● A population of students is working on group projects. Students can follow two strategies (S): workhard for the project (S=H) or free-ride (S=L).● In every course, groups of size n are formed at random. Students use the strategy determined at thebeginning of the course (i.e. S=H or S=L) in their group work.● Total group effort is determined by the composition of the group. In a group with h hard workers andl=n-h lazy workers total group effort is e=hH+lL (H and L being the effort put in by hard/lazyworkers).● When group projects are marked, every student in a group gets the same mark. The lecturerdetermines this mark as m=e/n (that is, by dividing total group effort by the number of students in agroup; the larger this number the better the mark.)● At the end of the semester groups are dissolved and every student rethinks his strategies for the nextsemester. He/she does this by selecting another student (a reference student) at random and comparinga measure ? based on marks and effort, =m-a*S (where a is a parameter and S=H or S=L dependingon strategy). The measure accounts for the mark obtained, but is lowered by the amount of effort spent.Very good marks without effort maximise the performance measure. If the reference student selectedfor comparison got a higher performance measure, the selected student will imitate the referencestudent's strategy in the next semester with a probability that is proportional to the difference in theperformance measure. Students will not imitate strategies from other students with worseperformance measures.● Students study forever (that is, take an infinite number of courses) and follow the same procedure (asoutlined above) for every course they take.Research questions to address:● Assuming we start with equal numbers of hard working and lazy workers, what is the composition ofthe group– After 4 years (i.e. 8 courses) if H=1 and L=0 and a=0.5.– In the long run (after an “infinite” number of years)?– How quickly is this equilibrium state reached?● How do the following parameters influence results:– Initial composition of the population– Group size (n)– Cost of effort, a– Contribution of hard workers to group effort (i.e. H and L) ...

February 1, 2023 · 5 min · jiezi

关于算法:CSC-413学习情况

Computer Science DepartmentSan Francisco State UniversityCSC 413Spring 2022Assignment 5 - DebuggerDue DateWednesday, May 18, BEFORE MIDNIGHTNo late submissions can be accepted for this assignment!Note that the due date applies to the last commit timestamp into the main branch of yourrepository.OverviewThe purpose of this assignment is to continue our work in the large compiler codebase, and implementa Debugger.You will be using your code for the Interpreter class, which must be copied into your github repositorywhen you begin the assignment via this assignment link.SubmissionYour assignment will be submitted using github. Only the “main” branch of your repository will begraded. Late submission is determined by the last commit time on the “main” branch. You are requiredto submit a documentation PDF named “documentation.pdf” in a “documentation” folder at the root ofyour project.Implementation RequirementsYou may create additional classes as needed to implement the requirements defined here, but mustimplement at least those classes listed here. If you decide to add additional classes, they must followobject oriented design principles - proper encapsulation and data hiding, and implementing a singleresponsibility.Project Setup ...

February 1, 2023 · 7 min · jiezi

关于算法:PROG2003云计算系统

PROG2003 – Cloud Systems DevelopmentAssignment 1PROG2003 Assignment 1Weight: 30% of your final markDue: Week 3 Monday (16 May 2022) at 11:00 PMSpecificationsYour task is to create a website that prints all the existing file details in an S3 bucket. To make thewebsite dynamic, you need to create a Cloud9 app that would work as a “backend” for the website.Your submission will be evaluated based on:• whether instructions have been followed;• correct functionality;• correct implementation; and• comments inside the programGetting HelpThis assignment, which is to be completed individually, is your chance to gain an understanding of thefundamental concepts of listing and creating S3 objects on which later learning will be based. It isimportant that you master these concepts yourself.Since you are mastering fundamental skills, you are permitted to work from the examples in theMySCU site or textbook, but you must acknowledge assistance from other textbooks or classmates. Inparticular, you must not use online material or help from others, as this would prevent you frommastering these concepts.This diagram will help you understand where you can get help:Encouraged Attribution Required Not acceptable Ask tutorBe aware that if you do get help from one of the red sources, you will be reported for academicmisconduct, which may have serious penalties. Please visit the following link for the guidelines:https://bit.ly/scuAcadMisconductLecturer Tutors OnlineForums RelativesStudentsoutside unit Hired coders Classmates PrivateTutorsOtherPROG2003 – Cloud Systems DevelopmentAssignment 1Overview: You have to create a website that prints the current file names and their sizes in an S3bucket. The website will be hosted in the same bucket and will have an index and an error page. Theindex page will print the file list and the error page will print some error messages. The index pagewould look like the screenshot below.You need to use the UA-provided AWS account for all assessment tasks. A personal AWS account isnot acceptable.Details: The details of the assignment tasks are described below.Part A: The website (6 marks): The index and error pages ideally would be the index.html anderror.html files. The error page will be displayed upon entering the wrong/invalid URL. The index pagewill print a list of names and sizes of the “current” files (i.e., known as objects in S3) within an S3bucket. If the bucket is empty then the index page should print a message “There are currently noobjects”. You need to host a static website with two pages (index.html, and error.html) in the bucket.You need to configure the bucket with the appropriate “bucket policy” and “public access” so thatyour website can be accessed publicly.The index page must reflect any changes to the number of files in the bucket. If you delete from oradd a file to the bucket, the index page must reflect that. You might be wondering how that would bepossible by a static website. To implement this “dynamic” functionality, you need to implement aCloud9 app that can: (a) list the current file names and their sizes; and (b) create (or overwrite) anindex file with the current file names and sizes in the bucket. The app will be executed each timebefore running the website so that the index.html always displays the updated list of current files andtheir sizes.Part B: The Cloud9 app (24 marks): The Cloud9 app will have two main features – listing all file names(i.e., object names or keys) as well as their sizes in the bucket, and creating a new file/object with thename/key “index.html” within the bucket. Upon serving, the index.html will display these names andsizes. It will print a message “no object available” if the bucket is empty. It has been taught during thetutorial that while creating an object in a bucket, you need to specify the content of the object. Thecontent of the index.html in this case will include the current object names and their sizes. You willget the names and sizes of the objects by implementing the listing feature. You need to embed thisinformation with HTML code to prepare the content of the index.html. The error.html will be verysimple and will display a relevant error message, e.g., page not found.Requirements: Your website and Cloud9 app must fulfil the following requirements. You will losemarks otherwise.PROG2003 – Cloud Systems DevelopmentAssignment 1• Your Cloud9 app must be named yourscuusernameA1App.• You will use a single bucket for the whole assignment and its name must be yourscuusernamea1-bucket.• Your Cloud9 app must have separate methods for the two features – listing and creating.• Your Cloud9 app must use exception handling and loop(s).• You must use AWS SDK v 2.x to implement the Cloud9 app.• You must implement the assignment in the SCU-provided AWS account, personal AWSaccount will not be accepted.• You need to add comments inside your source code.Solution Hints: Check the following hints for implementation.• A newly created object by default has a content type of “application/octet”. Such objectsbehave as attachments. This will not fulfil the purpose for a website, where the HTML pagesneed to serve. You need to explore the content-type property of the PutObjectRequest classfor this purpose.• You can use an unordered HTML list (<ul>…..</ul>) for the index.html to display the objectnames. Check this link out: https://www.w3schools.com/htm...Submission Checklist: The marker will access your AWS Academy workspace (provided by the UA),check your app, and directly mark your app from there. If your AWS console provided by the UA is notaccessible, you will lose a significant mark. You have to zip the app project folder and submit it inBlackboard as well. Blackboard submission list:• Zipped app folder for the Cloud9 app.• A text file containing the URL of the ...

February 1, 2023 · 5 min · jiezi

关于算法:ECS-170-程序解答过程

ECS 170: Spring 2022Homework Assignments 3 and 4 Due Date: Assignment 3 is due no later than Saturday, May 14, 2020, 9:00pm PDT.Assignment 4 is due no later than Saturday, May 21, 2020, 9:00pm PDT. The Assignment: Consider the game of Oska, whose rules are as follows: Oska is played on a board like that shown below. The two players face each other across theboard. Each player begins with four pieces, placed one to a square in each of the four squaresnearest that player. The white pieces always start at the top of the board.The player with the white pieces makes the first move, and the players alternate moves after that.A player may choose to move one of his or her pieces in one of these ways: ...

February 1, 2023 · 7 min · jiezi

关于算法:特定领域知识图谱融合方案文本匹配算法SimnetSimcseDiffcse

特定畛域常识图谱交融计划:文本匹配算法(Simnet、Simcse、Diffcse)本我的项目链接:https://aistudio.baidu.com/aistudio/projectdetail/5423713?contributionType=1 文本匹配工作在自然语言解决中是十分重要的根底工作之一,个别钻研两段文本之间的关系。有很多利用场景;如信息检索、问答零碎、智能对话、文本甄别、智能举荐、文本数据去重、文本类似度计算、自然语言推理、问答零碎、信息检索等,但文本匹配或者说自然语言解决依然存在很多难点。这些自然语言解决工作在很大水平上都能够形象成文本匹配问题,比方信息检索能够归结为搜索词和文档资源的匹配,问答零碎能够归结为问题和候选答案的匹配,复述问题能够归结为两个同义句的匹配。 0.前言:特定畛域常识图谱交融计划本我的项目次要围绕着特定畛域常识图谱(Domain-specific KnowledgeGraph:DKG)交融计划:文本匹配算法、常识交融学术界计划、常识交融业界落地计划、算法测评KG生产品质保障解说了文本匹配算法的综述,从经典的传统模型到孪生神经网络“双塔模型”再到预训练模型以及有监督无监督联结模型,期间也波及了近几年前沿的比照学习模型,之后提出了文本匹配技巧晋升计划,最终给出了DKG的落地计划。这边次要以原理解说和技术计划论述为主,之后会缓缓把我的项目开源进去,一起共建KG,从常识抽取到常识交融、常识推理、品质评估等争取走通残缺的流程。 0.1 具体细节参考第一篇我的项目:特定畛域常识图谱交融计划:技术常识前置【一】-文本匹配算法https://aistudio.baidu.com/aistudio/projectdetail/5398069?contributionType=1 0.2 特定畛域常识图谱(Domain-specific KnowledgeGraph:DKG)交融计划(重点!)在后面技术常识下能够看看后续的理论业务落地计划和学术计划 对于图神经网络的常识交融技术学习参考上面链接:[PGL图学习我的项目合集&数据集分享&技术演绎业务落地技巧[系列十]](https://aistudio.baidu.com/ai...) 从入门常识到经典图算法以及进阶图算法等,自行查阅食用! 文章篇幅无限请参考专栏按需查阅:NLP常识图谱相干技术业务落地计划和码源 1.特定畛域常识图谱常识交融计划(实体对齐):优酷畛域常识图谱为例计划链接:https://blog.csdn.net/sinat_39620217/article/details/128614951 2.特定畛域常识图谱常识交融计划(实体对齐):娱乐常识图谱构建之人物实体对齐计划链接:https://blog.csdn.net/sinat_39620217/article/details/128673963 3.特定畛域常识图谱常识交融计划(实体对齐):商品常识图谱技术实战计划链接:https://blog.csdn.net/sinat_39620217/article/details/128674429 4. 特定畛域常识图谱常识交融计划(实体对齐):基于图神经网络的商品异构实体表征摸索计划链接:https://blog.csdn.net/sinat_39620217/article/details/128674929 5.特定畛域常识图谱常识交融计划(实体对齐)论文合集计划链接:https://blog.csdn.net/sinat_39620217/article/details/128675199 论文材料链接:两份内容不雷同,且依照序号从小到大重要性顺次递加 常识图谱实体对齐材料论文参考(PDF)+实体对齐计划+特定畛域常识图谱常识交融计划(实体对齐) 常识图谱实体对齐材料论文参考(CAJ)+实体对齐计划+特定畛域常识图谱常识交融计划(实体对齐) 6.常识交融算法测试计划(常识生产品质保障)计划链接:https://blog.csdn.net/sinat_39620217/article/details/128675698 1.传统深度模型:SimNet短文本语义匹配(SimilarityNet, SimNet)是一个计算短文本类似度的框架,能够依据用户输出的两个文本,计算出类似度得分。 SimNet框架次要包含BOW、CNN、RNN、MMDNN等外围网络结构模式,提供语义类似度计算训练和预测框架, 实用于信息检索、新闻举荐、智能客服等多个利用场景解决语义匹配问题。 模型简介: 通过调用Seq2Vec中内置的模型进行序列建模,实现句子的向量示意。蕴含最简略的词袋模型和一系列经典的RNN类模型。 详情能够查看SimNet文件下的encoder文件 or 参考:https://github.com/PaddlePadd... __all__ = ["BoWEncoder", "CNNEncoder", "GRUEncoder", "LSTMEncoder", "RNNEncoder", "TCNEncoder"]模型模型介绍BOW(Bag Of Words)非序列模型,将句子示意为其所蕴含词的向量的加和CNN序列模型,应用卷积操作,提取部分区域地特色GRU(Gated Recurrent Unit)序列模型,可能较好地解决序列文本中长距离依赖的问题LSTM(Long Short Term Memory)序列模型,可能较好地解决序列文本中长距离依赖的问题Temporal Convolutional Networks (TCN)序列模型,可能更好地解决序列文本中长距离依赖的问题1.1 TCN:工夫卷积网络Temporal Convolutional Networks (TCN)工夫卷积网络,18年提出的时序卷积神经网络模型用来解决工夫序列预测的算法。其中,时序问题建模通常采纳RNN循环神经网络及其相干变种,比方LSTM、GRU等,这里将卷积神经网络通过收缩卷积达到抓取长时依赖信息的成果,TCN在一些工作上甚至能超过RNN相干模型。 作为一个新的序列剖析 model 它的特点次要有两个: 其卷积网络层层之间是有因果关系的,意味着不会有“漏接”的历史信息或是将来数据的状况产生,即使 LSTM 它有记忆门,也无奈完完全全的记得所有的历史信息,更何况要是该信息无用了就会逐步被忘记。这个 model 的架构能够伸缩自如的调整成任何长度,并能够依据输入端须要几个接口就 mapping 成对应的样子,这点和 RNN 的框架意思雷同,十分的灵便。论文链接:https://arxiv.org/pdf/1803.01271.pdf github链接:https://github.com/LOCUSLAB/tcn 时序问题的建模大家个别习惯性的采纳循环神经网络(RNN)来建模,这是因为RNN天生的循环自回归的构造是对工夫序列的很好的示意。传统的卷积神经网络个别认为不太适宜时序问题的建模,这次要因为其卷积核大小的限度,不能很好的抓取长时的依赖信息。 然而最近也有很多的工作显示,特定的卷积神经网络构造也能够达到很好的成果,比方Goolgle提出的用来做语音合成的wavenet,Facebook提出的用来做翻译的卷积神经网络。这就带来一个问题,用卷积来做神经网络到底是只实用于特定的畛域还是一种普适的模型? 本文就带着这个问题,将一种非凡的卷积神经网络——时序卷积网络(Temporal convolutional network, TCN)与多种RNN构造绝对比,发现在多种工作上TCN都能达到甚至超过RNN模型。 ...

February 1, 2023 · 5 min · jiezi

关于算法:3SMFE4统计算法分析

3SMFE4 LM Statistical Methods in Finance and EconomicsAdditional Tasks for Year 4 and PGT studentsThis will be assessed as 10% of course mark.__Before you work on this additional task sheet, please make sure you read the following information: Download the data; attach your R code to your solution.With R codes and all your solutions including figures together, it should not go more than 9 pages.I am responsible for clarification (NOT responsible for running programs nor explaining results for you).__The dataset cps4_small.csv contains the following information:Variables: wage educ exper hrswk married female metro midwest south west black asian ...

January 31, 2023 · 4 min · jiezi

关于算法:COMP30024人工智能算法

Project Part BPlaying the GameCOMP30024 Artificial Intelligence13 April 20221 OverviewIn this second part of the project, we will play the full two-player version of Cachex. Before you read thisspecification you should re-read the ‘Rules for the Game of Cachex ’ document. The rules of the game arethe same as before, however we have further clarified some points of confusion raised by students over thepast couple of weeks.The aims for Project Part B are for you and your project partner to (1) practice applying the game-playing techniques discussed in lectures and tutorials, (2) develop your own strategies for playing Cachex,and (3) conduct your own research into more advanced algorithmic game-playing techniques; all for thepurpose of creating the best Cachex–playing program the world has ever seen.The taskYour task is twofold. Firstly, you will design and implement a program to play the game of Cachex.That is, given information about the evolving state of the game, your program will decide on an actionto take on each of its turns (we provide a driver program to coordinate a game of Cachex between twosuch programs so that you can focus on implementing the game-playing strategy). Section 2 describes thisprogramming task in detail, including information about how our driver program will communicate withyour player program and how you can run the driver program.Secondly, you will write a report discussing the strategies your program uses to play the game, thealgorithms you have implemented, and other techniques you have used in your work, highlighting the mostimpressive aspects. Section 3 describes the intended structure of this document.The rest of this specification covers administrative information about the project. For assessment criteria,see Section 4. For submission and deadline information see Section 5. Please seek our help if you have anyquestions about this project.University of Melbourne 2022 12 The programYou must create a program in the form of a Python 3.6 module named with your team name.2.1 The Player classWhen imported, your module must define a class named Player with at least the following three methods: ...

January 31, 2023 · 15 min · jiezi

关于算法:FIT3152处理

Faculty ofInformationTechnology FIT3152 Data analytics – 2022: Assignment 2 Your task ● The objective of this assignment is to gain familiarity with classificationmodels using R.● This is an individual assignment.Value ● This assignment is worth 20% of your total marks for the unit.● It has 20 marks in total.SuggestedLength● 4 – 6 A4 pages (for your report) + extra pages as appendix (for your code)● Font size 11 or 12pt, single spacingDue Date 11.55pm Friday 20th May 2022Submission ● PDF file only. Naming convention: FirstnameSecondnameID.pdf● Via Moodle Assignment Submission.● Turnitin will be used for similarity checking of all submissions.LatePenalties● 10% (2 mark) deduction per calendar day for up to one week.● Submissions more than 7 calendar days after the due date will receive amark of zero (0) and no assessment feedback will be provided. ...

January 31, 2023 · 6 min · jiezi

关于算法:COMP3211解答

COMP3211 2021-22 Spring Semester Project on Multi-Agent Path Finding(For Individuals)Date assigned: Thursday, Mar 31.Due time: 23:59 on Tuesday, May 10.How to submit it: Submit your work as a zip file - see below for details.Penalties on late submission: 20% off each day (anytime after the due time is consideredlate by one day)This document is for those who choose to do the project individually. The tasks are exactlythe same as the ones for the team project except that you only need to consider two agents.1 Project descriptionImagine in a warehouse, a fleet of robots are designed to pick up packages from certainlocations and deliver them to certain ports. They should deliver the packages as efficientlyas possible, and at the same time, must not bump into each other or obstacles (no collision).In this project, you are going to design environment specific controllers for these robots.There are three environments called small, medium and large - see the appendix. Eachenvironment comes with two fixed goal positions, one for each robot.For each environment, you need to come up with 2 policies (pi1, pi2), one for each robot.A policy for a robot is a function from states to actions, with the following definitions ofstates and actions: A state is a tuple (l1, l2), where li is the current location of robot i. The actions are: up, down, right, left, nil, with their usual meaning.We will test your policies on some random initial states, and measure the quality of themby the sum of the numbers of actions the robots take to arrive at their respective goallocations.2 Project detailsThis project comes with a simulator and a code skeleton.2.1 File Description ...

January 31, 2023 · 6 min · jiezi

关于算法:CSE3BDC大数据处理

La Trobe UniversityDepartment of Computer Science and Computer EngineeringCSE3BDC Assignment 2022Objectives Gain in depth experience playing around with big data tools (Hive, SparkRDDs, and SparkSQL).Solve challenging big data processing tasks by finding highly efficient solutions.Experience processing three different types of real dataa. Standard multi-attribute data (Bank data)b. Time series data (Twitter feed data)c. Bag of words data.Practice using programming APIs to find the best API calls to solve your problem. Hereare the API descriptions for Hive, Spark (especially spark look under RDD. There are a lotof really useful API calls).a) [Hive] https://cwiki.apache.org/conf...b) [Spark] http://spark.apache.org/docs/...c) [Spark SQL] https://spark.apache.org/docs...https://spark.apache.org/docs...thttps://spark.apache.org/docs...If you are not sure what a spark API call does, try to write a small example and try it inthe spark shellThis assignment is due 10:00 a.m. on Friday 20th of May, 2022.Penalties are applied to late assignments (accepted up to 5 business days after the due dateonly). Five precent is deducted per business day late. A mark of zero will be assigned toassignments submitted more than 5 days late.This is an individual assignment. You are not permitted to work as a part of a group whenwriting this assignment.Submission checklist• Ensure that all of your solutions read their input from the full data files (not the smallexample versions)• Check that all of your solutions run without crashing in the docker containers that youused in the labs.• Delete all output files• Archive up everything into a single zip file and submit your assignment via LMSCopying, PlagiarismPlagiarism is the submission of somebody else’s work in a manner that gives the impressionthat the work is your own. For individual assignments, plagiarism includes the case where twoor more students work collaboratively on the assignment. The Department of ComputerScience and Computer Engineering treats plagiarism very seriously. When it is detected,penalties are strictly imposed.Expected quality of solutionsa) In general, writing more efficient code (less reading/writing from/into HDFS and lessdata shuffles) will be rewarded with more marks.b) This entire assignment can be done using the docker containers supplied in the labsand the supplied data sets without running out of memory. It is time to show yourskills!c) I am not too fussed about the layout of the output. As long as it looks similar to theexample outputs for each task. That will be good enough. The idea is not to spend toomuch time massaging the output to be the right format but instead to spend the time tosolve problems.d) For Hive queries. We prefer answers that use less tables.The questions in the assignment will be labelled using the following:• [Hive]o Means this question needs to be done using Hive• [Spark RDD]o Means this question needs to be done using Spark RDDs, you are not allowedto use any Spark SQL features like dataframe or datasets.• [Spark SQL]o Means this question needs to be done using Spark SQL and therefore you arenot allowed to use RDDs. In addition, you need to do these questions using thespark dataframe or dataset API, do not use SQL syntax.Assignment structure:• A script which puts all of the data files into HDFS automatically is provided for you.Whenever you start the docker container again you will need to run the following scriptto upload the data to HDFS again, since HDFS state is not maintained across dockerruns:$ bash put_data_in_hdfs.shThe script will output the names of all of the data files it copies into HDFS. If youdo not run this script, solutions to the Spark questions will not work since theyload data from HDFS.• For each Hive question a skeleton .hql file is provided for you to write your solution in.You can run these just like you did in labs:$ hive -f Task_XX.hql• For each Spark question, a skeleton project is provided for you. Write your solution inthe .scala file in the src directory. Build and run your Spark code using the providedscripts:$ bash build_and_run.shTips:Look at the data files before you begin each task. Try to understand what you aredealing with!For each subtask we provide small example input and the corresponding output in theassignment specifications below. These small versions of the files are also suppliedwith the assignment (they have “-small” in the name). It’s a good idea to get yoursolution working on the small inputs first before moving on to the full files.In addition to testing the correctness of your code using the very small example input.You should also use the large input files that we provide to test the scalability of yoursolutions.It can take some time to build and run Spark applications from .scala files. So for theSpark questions it’s best to experiment using spark-shell first to figure out a workingsolution, and then put your code into the .scala files afterwards.Task 1: Analysing Bank Data [38 marks total]We will be doing some analytics on real data from a Portuguese banking institution1. The datais stored in a semicolon (“;”) delimited format.The data is supplied with the assignment at the following locations:Small version Full versionTask_1/Data/bank-small.csv Task_1/Data/bank.csvThe data has the following attributesAttributeindexAttributenameDescriptionage numericjob type of job (categorical: "admin.", "unknown", "unemployed","management", "housemaid", "entrepreneur", "student",“blue-collar", "self-employed", "retired", "technician", "services")marital marital status (categorical: "married", "divorced", "single"; note:"divorced" means divorced or widowed)education (categorical: "unknown", "secondary", "primary", "tertiary")default has credit in default? (binary: "yes", "no")balance average yearly balance, in euros (numeric)housing has housing loan? (binary: "yes", "no")loan has personal loan? (binary: "yes", "no")contact contact communication type (categorical: “unknown", "telephone","cellular")day last contact day of the month (numeric)month last contact month of year (categorical: "jan", "feb", "mar", ...,"nov", "dec")duration last contact duration, in seconds (numeric)campaign number of contacts performed during this campaign and for thisclient (numeric, includes last contact)pdays number of days that passed by after the client was last contactedfrom a previous campaign (numeric, -1 means client was notpreviously contacted)previous number of contacts performed before this campaign and for thisclient (numeric)poutcome outcome of the previous marketing campaign (categorical:"unknown","other","failure","success")termdeposit has the client subscribed a term deposit? (binary: "yes","no"): Banking data source: http://archive.ics.uci.edu/ml...Here is a small example of the bank data that we will use to illustrate the subtasks below (weonly list a subset of the attributes in this example, see the above table for the description ofthe attributes):job marital education balance loanmanagement Married tertiary 2143 Yestechnician Divorced secondary 29 Yesentrepreneur Single secondary 2 Noblue-collar Married unknown 1506 Noservices Divorced secondary 829 Yestechnician Married tertiary 929 YesManagement Divorced tertiary 22 Notechnician Married primary 10 NoPlease note we specify whether you should use [Hive] or [Spark RDD] for each subtask at thebeginning of each subtask.a) [Hive] Report the number of clients of each job category. Write the results to“Task_1a-out”. For the above small example data set you would report the following(output order is not important for this question):"blue-collar" 1"entrepreneur" 1"management" 2"services" 1"technician" 3[8 marks]b) [Hive] Report the average yearly balance for all people in each education category.Write the results to “Task_1b-out”. For the small example data set you would reportthe following (output order is not important for this question):"primary" 10.0"secondary" 286.6666666666667"tertiary" 1031.3333333333333"unknown" 1506.0[8 marks]c) [Spark RDD] Group balance into the following three categories:a. Low: -infinity to 500b. Medium: 501 to 1500 =>c. High: 1501 to +infinityReport the number of people in each of the above categories. Write the results to“Task_1c-out” in text file format. For the small example data set you should get thefollowing results (output order is not important in this question):(High,2)(Medium,2)(Low,4)[10 marks]d) [Spark RDD] Sort all people in ascending order of education. For people with thesame education, sort them in descending order by balance. This means that all peoplewith the same education should appear grouped together in the output. For eachperson report the following attribute values: education, balance, job, marital, loan.Write the results to “Task_1d-out” in text file format (multiple parts are allowed). Forthe small example data set you would report the following:("primary",10,"technician","married","no")("secondary",829,"services","divorced","yes")("secondary",29,"technician","divorced","yes")("secondary",2,"entrepreneur","single","no")("tertiary",2143,"management","married","yes")("tertiary",929,"technician","married","yes")("tertiary",22,"management","divorced","no")("unknown",1506,"blue-collar","married","no")[12 marks] Task 2: Analysing Twitter Time Series Data [32 marks]In this task we will be doing some analytics on real Twitter data2. The data is stored in a tab(“\t”) delimited format.The data is supplied with the assignment at the following locations:Small version Full versionTask_2/Data/twitter-small.tsv Task_2/Data/twitter.tsvThe data has the following attributesAttributeindexAttribute name DescriptiontokenType In our data set all rows have Token type of hashtag. Sothis attribute is useless for this assignment.month The year and month specified like the following:YYYYMM. So 4 digits for year followed by 2 digits formonth. So like the following 200905, meaning the yearand month of Maycount An integer representing the number tweets of this hashtag for the given year and monthhashtagName The #tag name, e.g. babylove, mydate, etc.Here is a small example of the Twitter data that we will use to illustrate the subtasks below:Token type Month count Hash Tag Namehashtag 200910 2 babylovehashtag 200911 2 babylovehashtag 200912 90 babylovehashtag 200812 100 mycoolwifehashtag 200901 201 mycoolwifehashtag 200910 1 mycoolwifehashtag 200912 500 mycoolwifehashtag 200905 23 abchashtag 200907 1000 abc: Twitter data source: http://www.infochimps.com/dat...a) [Spark RDD] Find the single row that has the highest count and for that row report themonth, count and hashtag name. Print the result to the terminal output using println.So, for the above small example data set the result would be:month: 200907, count: 1000, hashtagName: abc[6 marks]b) [Do twice, once using Hive and once using Spark RDD] Find the hash tag name thatwas tweeted the most in the entire data set across all months. Report the total numberof tweets for that hash tag name. You can either print the result to the terminal oroutput the result to a text file. So, for the above small example data set the outputwould be:abc 1023[12 marks total: 6 marks for Hive and 6 marks for Spark RDD]c) [Spark RDD] Given two months x and y, where y > x, find the hashtag name that hasincreased the number of tweets the most from month x to month y. Ignore the tweetsin the months between x and y, so just compare the number of tweets at month x andat month y. Report the hashtag name, the number of tweets in months x and y. Ignoreany hashtag names that had no tweets in either month x or y. You can assume thatthe combination of hashtag and month is unique. Therefore, the same hashtag andmonth combination cannot occur more than once. Print the result to the terminaloutput using println. For the above small example data set:Input x = 200910, y = 200912Output hashtagName: mycoolwife, countX: 1, countY: 500For this subtask you can specify the months x and y as arguments to the script. This isrequired to test on the full-sized data. For example:$ bash build_and_run.sh 200901 200902[14 marks]Task 3: Indexing Bag of Words data [30 marks]In this task you are asked to create a partitioned index of words to documents that contain thewords. Using this index you can search for all the documents that contain a particular wordefficiently.The data is supplied with the assignment at the following locations3:Small version Full versionTask_3/Data/docword-small.txt Task_3/Data/docword.txtTask_3/Data/vocab-small.txt Task_3/Data/vocab.txtThe first file is called docword.txt, which contains the contents of all the documents stored inthe following format:AttributeindexAttribute name DescriptiondocId The ID of the document that contains the wordvocabId Instead of storing the word itself, we store an ID from thevocabulary file.count An integer representing the number of times this wordoccurred in this document.The second file called vocab.txt contains each word in the vocabulary, which is indexed byvocabIndex from the docword.txt file.Here is a small example content of the docword.txt file.docId vocabId count3 6003 7022 1205 2002 5001 1005 20004 1223 12001 1000: Data source: http://archive.ics.uci.edu/ml...Here is an example of the vocab.txt filevocabId wordplanecarmotorbiketruckboatComplete the following subtasks using Spark:a) [spark SQL] Calculate the total count of each word across all documents. List thewords in ascending alphabetical order. Write the results to “Task_3a-out” in CSVformat (multiple output parts are allowed). So for the above small example input theoutput would be the following (outputs with multiple parts will be considered in order ofthe part number):boat,2200car,620motorbike,2502plane,1100truck,122Note: spark SQL will give the output in multiple files. You should ensure that thedata is sorted globally across all the files (parts). So, all words in part 0, will bealphabetically before the words in part 1.[8 marks]b) [spark SQL] Create a dataframe containing rows with four fields: (word, docId, count,firstLetter). You should add the firstLetter column by using a UDF which extracts thefirst letter of word as a String. Save the results in parquet format partitioned byfirstLetter to docwordIndexFilename. Use show() to print the first 10 rows of thedataframe that you saved.So, for the above example input, you should see the following output (the exact ...

January 21, 2023 · 12 min · jiezi

关于算法:5CCE2SA信号与处理

SIGNALS & SYSTEMS5CCE2SASCOURSEWORK 2There are 4 Questions, answer all.Detailed answers and careful sketches are required foreach one of the questions. Upload clearly scanned copies of your written answers bythe deadline, as indicated on Keats. Question one (total: 30 marks): The Fourier transform of a continuous-time signal (), i.e., (), is given as a) Find the corresponding time-domain signal ().(10 marks) b) Given that the signal () in part (a) is a periodic function of time, findthe fundamental (radian) frequency and the Fourier series coefficients ofthe signal ().(10 marks) ...

January 21, 2023 · 2 min · jiezi

关于算法:ELECTENG-733信号处理解

Last Modified: 10/03/2022ELECTENG 733: Signal ProcessingAssignment-1 Cover SheetAvailable from 11 March to 21 March.All answers are to be submitted before 11:59 p.m. on 21 MarchINSTRUCTIONSAssignment total marks: 70Assessment Grading: This assignment contributes 10% towards your final course mark. To get full credit, you must comprehensively answer all questions correctly. There are SIX questions in total. Attempt all questions. You must show all your working to receive full credit for each solution. If you believe you need further information than that provided, make the appropriate engineeringassumption(s), state them clearly, and continue with your answer. Prepare your hand-written solutions in PDF format, and submit your completed work, with this coversheet, electronically via Canvas before the deadline. Late submissions will not be accepted. One day delay allowed, but 30% of the total mark will bededucted.The submitted pages must be of A4 size. Begin each question on a new page. It is the responsibility of students to ensure that their names and ID numbers are correctly depicted, andthe cover sheet is signed.ASSESSMENT LOGISTICS The assessment must be taken completely alone. Showing or sharing it with anyone isconsidered copying and lead to zero mark in the assignment for all contributed parties. You may not consult, collaborate, or discuss, with any other person regarding the materials relatingto, or directly from, the assessment. Anything you submit must be your own unaided work. Any questions and/or clarifications about the assessment can only be sent to Waleed via the e-mail(w.abdulla@auckland.ac.nz). DO NOT use Piazza for any query regarding the assessment.Failure to comply with any of the rules above may result in voiding your submission.I hereby accept all of the rules and instructions in this cover page, and declare that I will NOT discussor otherwise communicate in any way, or via any channel, with any individual within or outside theuniversity regarding the content of this assessment before the assignment submission due date.Family Name: Office Use OnlyGiven Name: Q1: Q4:Username: Q2:AUID: Q3:Total Mark:SignatureLecturer: Waleed AbdullaQ5:Q6:Student Name: Student ID:2 ...

January 19, 2023 · 3 min · jiezi

关于算法:COMP30023题型解说

COMP30023 Project 1Lock, Lock, ..., DeadlockOut date: March 14, 2022Due date: No later than 14:59 March 29, 2022 AEDTWeight: 15% of the final markBackgroundIn this project you will familiarise yourself with detection of deadlocks in a multi-process environment.Please note that you do not need to lock any files to implement this project.We strongly advise you to start working on the project as soon as possible and read the whole spec beforebeginning implementation.1 Detecting and breaking locksYou will be given a description of running processes and the files they need to execute, where each processis associated with two files. The first one is the file that the process has locked and the second one isthe file that it is waiting to lock. The goal of your program is to determine whether given the currentresource allocation and requests there is a deadlock or not. Please see Week 2 Lecture 2 on deadlocksfor more information.If there is no deadlock, you are asked to compute the minimum execution time required for all processesto finish given the following specification. If a process locked a file, it takes 1 time unit to operate onthis file and release it. If a process requested a file, after a process is given this file, it takes 1 timeunit to operate on this file and release it. Hence, any process takes at least 2 time units to finish. If kprocesses have requested the same file, it will take k time units for the processes to finish, where k ≥ 1.Processes that have locked or requested distinct files can operate in parallel. That is, if two processeshave requested two different files then it will take a total of 1 time unit for the processes to operate onthese files if both files are not locked by other processes.If there is a deadlock, you are asked to return process(es) that have to be terminated in order to resolvethe deadlock.2 Program SpecificationYour program will be invoked via the command line. It must be called detect and take the followingcommand line arguments. The arguments can be passed in any order but you can assume that theywill be passed exactly once.-f filename specifies the path to the file describing requests.-e is an optional parameter, which when provided requires your code to compute execution time. If thisoption is not given, your code should identify presence or absence of deadlocks and which processesneed to be terminated to resolve deadlock(s).-c is an optional parameter, which when provided invokes your file per process allocation from Section 4.The file specified by filename contains the processes and their locked and requested resources in thefollowing format.Each line of the file corresponds to a process and consists of a space-separated tuple:process-id space file-id space file-id1where the first file-id is the file that the process has locked and the second file-id is the file requested bythe process. You can assume that all process-ids will be distinct integers in the domain of [0, 232). Youcan assume that all file-ids will be integers in the domain of [0, 232).Example: ./detect -f resources.txtThe detection program is required to determine if there is a deadlock in the current resource allocation.For example resources.txt with the following information:0 1 31 2 7describes a system where process 0 has locked file 1 and is waiting for file 3 while process 1 has lockedfile 2 and waiting for file 7.If resources.txt has the following information:0 1 21 2 1then the system has processes 0 and 1, with locks on files 1 and 2, respectively. In addition, process 0requested file 2 while process 1 requested file 1. Hence, there is a deadlock.Each line (including the last) will be terminated with a LF (ASCII 0x0a) control character.We will not give malformed input (e.g., negative ids for processes and files, non-space delimiters, situationswhere more than one process locked the same file).3 Expected OutputIn order for us to verify that your code meets the specification, it should print to standard output (stderrwill be ignored) the following information. You should print each line of the expected output followedby new line.To get full marks you will be required to print the whole transcript as described below. However, youcan get marks for each task individually as long as your output for that specific task is correct. Forexample, you can get full marks for Task 1 and 2 without having implemented later tasks.Task 1. Systems statistics You are asked to print the total number of processes and files in thesystem (both locked and requested).Task 2. Execution time (No deadlock) You can assume that there is no deadlock in the fileallocation for this task only. You are asked to print minimum execution time required for all processesto finish given the specification in Section 1.Task 3. Deadlock detection Your program should print No deadlocks if there are no deadlocks, orDeadlock detected if there is at least one deadlock.Tasks 4,5. Breaking deadlocks If your program returns Deadlock detected, you are also asked toreturn a list of processes that need to be terminated to break the deadlock. You should print them ona separate line, separated by spaces. If there are many processes which can be terminated to break aparticular deadlock, choose the process with the smallest ID.You will need to print the minimum number of processes that need to be terminated to remove alldeadlocks. If there is more than one process that need to be terminated, separate them by space andprint them in ascending order, sorted by process ID.Sample output 1Given resources.txt with the following information:0 1 21 2 12On ./detect -f resources.txt your program should print:Processes 2\nFiles 2\nDeadlock detected\nTerminate 0\nSample output 2Given resources.txt with the following information:0 1 31 2 4On ./detect -e -f resources.txt your program should print:Processes 2\nFiles 4\nExecution time 2\nsince processes can proceed in parallel with each other, with each process taking 2 time units as each isoperating on 2 files sequentially.4 Challenge taskIf a deadlock was detected, you are asked to come up with a transcript that allocates files to processesin such a way that a deadlock is avoided. That is, you can assume that all resources are available andno files have been locked yet. Instead, the two file-ids associated with a process in the input file are twofiles required for the process to execute. A process can only execute if it obtains both files at the sametime. Once it obtains the files, it locks them and releases at the next time unit. Hence, a file cannot beallocated to more than one process at any given time. A naive way of allocating files to processes wouldbe to allocate both files to a process, then, once this process releases them (i.e., at the next time unit),proceed to allocating files to the next process. This would however lead to a slow execution that doesnot have any parallelism. Your task is instead to allocate files to separate processes at the same timewhile avoiding deadlocks.In order for us to evaluate whether your allocation avoids deadlocks, you are asked to print an allocationtranscript in the following format. If a process is allocated its two files, print on a separate linetime space process-id space file-id comma file-idThe order in which the file-ids appear above is up to you. You can assume that the process willautomatically release the files allocated to it at the next time unit, so you do not have to print anythingto release the files. You are also asked to print the total simulation time, i.e., the time when all processeshave been given all the files and released them. Time should start at 0, that is the first line of yourtranscript will have 0 as time.You will be required to explain how your algorithm is more efficient than naive sequential allocation ina short report.Sample output 3Given resources.txt with the following information:0 1 21 2 32 3 43 4 1./detect -f resources.txt -c could print:0 0 1,2\n0 2 3,4\n1 1 2,3\n1 3 4,1\nSimulation time 2\n3Note that with -c your program should not print the output required in Section 3.5 Marking CriteriaThe marks are broken down as follows:Task # and description Marks ...

January 19, 2023 · 13 min · jiezi

关于算法:COMP9315-问题求解与算法

3/15/22, 2:09 PM COMP9315 22T1 - Assignment 1https://cgi.cse.unsw.edu.au/~... 1/8DeadlinePre-requisites:Late Penalty:Marks:Submission:COMP9315 22T1 Assignment 1Adding a PersonName Data Type toPostgreSQLDBMS ImplementationLast updated: Tuesday 22nd February 2:16pmMost recent changes are shown in red ... older changes are shown in brown.AimsThis assignment aims to give youan understanding of how data is treated inside a DBMSpractice in adding a new base type to PostgreSQLThe goal is to implement a new data type for PostgreSQL, complete with input/output functions,comparison operators, formatting functions, and the ability to build indexes on values of the type.SummaryFriday 18 March, 9:00pmbefore starting this assignment, it would be useful to complete Prac Work P040.04 marks off the ceiling mark for each hour lateThis assignment contributes 15 marks toward your total mark for this course.Webcms3 > Assignments > Ass1 Submission > Make Submissionor, on CSEmachines, give cs9315 ass1 pname.c pname.sourceMake sure that you read this assignment specification carefully and completely before starting workon the assignment.Questions which indicate that you haven't done this will simply get the response "Please read thespec".We use the following names in the discussion belowPG_CODE ... the directory where your PostgreSQL source code is located (typically/localstorage/YOU/postgresql-14.1/)PG_HOME ... the directory where you have installed the PostgreSQL binaries (typically/localstorage/YOU/pgsql/bin/)PG_DATA ... the directory where you have placed PostgreSQL's data (typically/localstorage/YOU/pgsql/data/)PG_LOG ... the file where you send PostgreSQL's log output (typically/localstorage/YOU/pgsql/data/log)IntroductionPostgreSQL has an extensibility model which, among other things, provides a well-defined processfor adding new data types into a PostgreSQL server. This capability has led to the development by3/15/22, 2:09 PM COMP9315 22T1 - Assignment 1https://cgi.cse.unsw.edu.au/~... 2/8PostgreSQL users of a number of types (such as polygons) which have become part of the standarddistribution. It also means that PostgreSQL is the database of choice in research projects which aimto push the boundaries of what kind of data a DBMS can manage.In this assignment, we will be adding a new data type for dealing with people's names. "Hmmm", yousay, "but aren't they just text strings, typically implemented as two attributes, one for family nameand one for given names?". That may be true, but making names into a separate base data typeallows us to explore how we store and manipulate them.One common way of writing names (e.g. used in UNSW student systems) isShepherd,John AndrewLin,XueminEilish,BillieMartin, Eric AndreLakshminarasimhan,Venkateswaran ChandrasekaraMarshall-Martin, Sally AngelaFeatherstone,Albert Basil Ernest George Harold Randolph Williami.e.FamilyName,GivenNamesWe give a more precise description of what text strings are valid PersonNames below.Adding Data Types in PostgreSQLThe process for adding new base data types in PostgreSQL is described in the following sections ofthe PostgreSQL documentation:37.13 User-defined Types37.10 C-Language Functions37.14 User-defined OperatorsSQL: CREATE TYPESQL: CREATE OPERATORSQL: CREATE OPERATOR CLASSSection 37.13 uses an example of a complex number type, which you can use as a starting point fordefining your PersonName data type (see below). There are other examples of new data types underthe directories:PG_CODE/contrib/chkpass/ ... an auto-encrypted password datatypePG_CODE/contrib/citext/ ... a case-insensitive character string datatypePG_CODE/contrib/seg/ ... a confidence-interval datatypeThese may or may not give you some useful ideas on how to implement the PersonName data type.For example, many of these data types are fixed-size, while PersonNames are variable-sized. Apotentially useful example of implementing variable-sized types can be found in:PG_CODE/src/tutorial/funcs.c ... implementation of several data typesSetting Up3/15/22, 2:09 PM COMP9315 22T1 - Assignment 1https://cgi.cse.unsw.edu.au/~... 3/8You ought to start this assignment with a fresh copy of PostgreSQL, without any changes that youmight have made for the Prac exercises (unless these changes are trivial). Note that you only needto configure, compile and install your PostgreSQL server once for this assignment. All subsequentcompilation takes place in the src/tutorial directory, and only requires modification of the filesthere.Once you have re-installed your PostgreSQL server, you should run the following commands:$ cd PG_CODE/src/tutorial$ cp complex.c pname.c$ cp complex.source pname.sourceNote the pname.* files will contain many references to complex; I do not want to see any remainingoccurences of the word complex in the files that you eventually submit. These files simply provide atemplate in which you create your PersonName type.Once you've made the pname.* files, you should also edit the Makefile in this directory and add thegreen text to the following lines:MODULES = complex funcs pnameDATA_built = advanced.sql basics.sql complex.sql funcs.sql syscat.sql pname.sqlThe rest of the work for this assignment involves editing only the pname.c and pname.source files.In order for the Makefile to work properly, you must use the identifier OBJWD in the pname.sourcefile to refer to the directory holding the compiled library. You should never modify directly thepname.sql file produced by the Makefile. Place all of your C code in the pname.c file; do notcreate any other *.c files.Note that your submitted versions of pname.c and pname.source should not contain any referencesto the complex type. Make sure that the documentation (comments in program) describes the codethat you wrote. Leaving the word complex anywhere in a pname.* file will cost 1 mark.The Person Name Data TypeWe wish to define a new base type PersonName to represent people's names, in the formatFamilyName,GivenNames. We also aim to define a useful set of operations on values of typePersonName and wish to be able to create indexes on PersonName attributes. How you representPersonName values internally, and how you implement the functions to manipulate them internally, isup to you. However, they must satisfy the requirements below.Once implemented correctly, you should be able to use your PostgreSQL server to build thefollowing kind of SQL applications:create table Students (zid integer primary key,name PersonName not null,degree text,-- etc. etc.);insert into Students(zid,name,degree) values(9300035,'Shepherd, John Andrew', 'BSc(Computer Science)'),3/15/22, 2:09 PM COMP9315 22T1 - Assignment 1https://cgi.cse.unsw.edu.au/~... 4/8(5012345,'Smith, Stephen', 'BE(Hons)(Software Engineering)');create index on Students using hash (name);select a.zid, a.name, b.zidfrom Students a join Students b on (a.name = b.name);select family(name), given(name), show(name)from Students;select name,count(*)from Studentsgroup by name;Having defined a hash-based file structure, we would expect that the queries would make use of it.You can check this by adding the keyword EXPLAIN before the query, e.g.db=# explain analyze select * from Students where name='Smith,John';which should, once you have correctly implemented the data type and loaded sufficient data, showthat an index-based scan of the data is being used. Note that this will only be evident if you use alarge amount of data (e.g. one of the larger test data samples to be provided).Person Name valuesValid PersonNames will have the above format with the following qualifications:there may be a single space after the commathere will be no people with just one name (e.g. no Prince, Jesus, Aristotle, etc.)there will be no numbers (e.g. noGates, William 3rd)there will be no titles (e.g. no Dr, Prof, Mr, Ms)there will be no initials (e.g. no Shepherd,John A)In other words, you can ignore the possibility of certain types of names while implementing yourinput and output functions.A more precise definition can be given using a BNF grammar:PersonName ::= Family','Given | Family', 'GivenFamily ::= NameListGiven ::= NameListNameList ::= Name | Name' 'NameListName ::= Upper LettersLetter ::= Upper | Lower | PuncLetters ::= Letter | Letter LettersUpper ::= 'A' | 'B' | ... | 'Z'3/15/22, 2:09 PM COMP9315 22T1 - Assignment 1https://cgi.cse.unsw.edu.au/~... 5/8Lower ::= 'a' | 'b' | ... | 'z'Punc ::= '-' | "'"You should not make any assumptions about the maximum length of a PersonName.Under this syntax, the following are valid names:Smith,JohnSmith, JohnO'Brien, Patrick SeanMahagedara Patabendige,Minosha Mitsuaki SenakasiriI-Sun, Chen WangClifton-Everest,Charles EdwardThe following names are not valid in our system:Jesus # no single-word namesSmith , Harold # space before the ","Gates, William H., III # no initials, too many commasA,B C # names must at least 2 lettersSmith, john # names begin with an upper-case letterThink about why each of the above is invalid in terms of the syntax definition.Important: for this assignment, we define an ordering on names as follows:the ordering is determined initially by the ordering on the Family Nameif the Family Names are equal, then the ordering is determined by the Given Namesordering of parts is determined lexicallyThere are examples of how this works in the section on Operations on PersonNames below.Representing Person NamesThe first thing you need to do is to decide on an internal representation for your PersonName datatype. You should do this, however, after you have looked at the description of the operators below,since what they require may affect how you decide to structure your internal PersonName values.When you read strings representing PersonName values, they are converted into your internal form,stored in the database in this form, and operations on PersonName values are carried out using thisdata structure. It is useful to define a canonical form for names, which may be slightly different to theform in which they are read (e.g. "Smith, John" might be rendered as "Smith,John"). When youdisplay PersonName values, you should show them in canonical form, regardless of how they wereentered or how they are stored.The first functions you need to write are ones to read and display values of type PersonName. Youshould write analogues of the functions complex_in(), complex_out that are defined in the filecomplex.c. Call them, e.g., pname_in() and pname_out(). Make sure that you use the V1 stylefunction interface (as is done in complex.c).Note that the two input/output functions should be complementary, meaning that any string displayedby the output function must be able to be read using the input function. There is no requirement foryou to retain the precise string that was used for input (e.g. you could store the PersonName value3/15/22, 2:09 PM COMP9315 22T1 - Assignment 1https://cgi.cse.unsw.edu.au/~... 6/8internally in a different form such as splitting it into two strings: one for the family name(s), and onefor the given name(s)).One thing that pname_in() must do is determine whether the name has the correct structure(according to the grammar above). Your pname_out() should display each name in a format thatcan be read by pname_in().Note that you are not required to define binary input/output functions, called receive_function andsend_function in the PostgreSQL documentation, and called complex_send and complex_recv inthe complex.cfile.As noted above, you cannot assume anything about the maximum length of names. If your solutionuses two fixed-size buffers (one for family, one for given) then your mark is limited to 6/10.Operations on person namesYou must implement all of the following operations for the PersonName type:PersonName = PersonName ... two names are equalTwo PersonNames are equivalent if, they have the same family name(s) and the same givenname(s).PersonName : Smith,JohnPersonName : Smith, JohnPersonName : Smith, John DavidPersonName : Smith, James(PersonName = PersonName ) is true(PersonName = PersonName ) is true(PersonName = PersonName ) is true (commutative)(PersonName = PersonName ) is false(PersonName = PersonName ) is falsePersonName > PersonName ... the first PersonName is greater than the secondPersonName is greater than PersonName if the Family part of PersonName is lexicallygreater than the Family part of PersonName . If the Family parts are equal, then PersonNameis greater than PersonName if the Given part of PersonName is lexically greater than theGiven part of PersonName .PersonName : Smith,JamesPersonName : Smith,JohnPersonName : Smith,John DavidPersonName : Zimmerman, Trent(PersonName > PersonName ) is false(PersonName > PersonName ) is false(PersonName > PersonName ) is true(PersonName > PersonName ) is false(PersonName > PersonName ) is trueOther operations: <>, >=, <, <=https://cgi.cse.unsw.edu.au/~... 7/8You should also implement the above operations, whose semantics is hopefully obvious fromthe descriptions above. The operators can typically be implemented quite simply in terms of thefirst two operators.family(PersonName) returns just the Family part of a namePersonName : Smith,JamesPersonName : O'Brien,Patrick SeanPersonName : Mahagedara Patabendige,Minosha Mitsuaki SenakasirPersonName : Clifton-Everest,David Ewanfamily(PersonName ) returns "Smith"family(PersonName ) returns "O'Brien"family(PersonName ) returns "Mahagedara Patabendige"family(PersonName ) returns "Clifton-Everest"given(PersonName) returns just the Given part of a namePersonName : Smith,JamesPersonName : O'Brien,Patrick SeanPersonName : Mahagedara Patabendige,Minosha Mitsuaki SenakasirPersonName : Clifton-Everest,David Ewangiven(PersonName ) returns "James"given(PersonName ) returns "Patrick Sean"given(PersonName ) returns "Minosha Mitsuaki Senakasir"given(PersonName ) returns "David Ewan"show(PersonName) returns a displayable version of the nameIt appends the entire Family name to the first Given name (everything before the first space, ifany), separated by a single space.PersonName : Smith,JamesPersonName : O'Brien,Patrick SeanPersonName : Mahagedara Patabendige,Minosha Mitsuaki SenakasirPersonName : Clifton-Everest,David EwanPersonName : Bronte,Greta-Anna Maryanneshow(PersonName ) returns "James Smith"show(PersonName ) returns "Patrick O'Brien"show(PersonName ) returns "Minosha Mahagedara Patabendige"show(PersonName ) returns "David Clifton-Everest"show(PersonName ) returns "Greta-Anna Bronte"Hint: test out as many of your C functions as you can outside PostgreSQL (e.g. write a simple testdriver) before you try to install them in PostgreSQL. This will make debugging much easier.You should ensure that your definitions capture the full semantics of the operators (e.g. specifycommutativity if the operator is commutative). You should also ensure that you provide sufficientdefinitions so that users of the PersonName type can create hash-based indexes on an attribute oftype PersonName.3/15/22, 2:09 PM COMP9315 22T1 - Assignment 1https://cgi.cse.unsw.edu.au/~... 8/8SubmissionYou need to submit two files: pname.c containing the C functions that implement the internals of thePersonName data type, and pname.source containing the template SQL commands to install thePersonName data type into a PostgreSQL server. Do not submit the pname.sql file, since it containsabsolute file names which are not helpful in our test environment.Have fun, jas ...

January 19, 2023 · 10 min · jiezi

关于算法:G5114-python算法

Advanced Natural Language Engineering (G5114):Assessed courseworkFebruary 21, 2022Format Submit a single zip file containing at least 1 pdf and an appendix of your code (which may be a.ipynb or a .py file)Word Count 8 pages (approx. 3000 words) plus code appendixMarking You will be told your mark and receive feedback via Canvas before Friday 20tt MayWeighting This assignment is worth 60% of your mark for this module.1 Practical assignment (3000 words)The Microsoft Research Sentence Completion Challenge (Zweig and Burges, 2011) requires a system tobe able to predict which is the most likely word (from a set of 5 possibilities) to complete a sentence. Inthe labs you have evaluated using unigram and bigram models. In this assignment you are expected toinvestigate at least 2 extensions or alternative approaches to making predictions. Your solution doesnot need to be novel. You might choose to investigate 2 of the following approaches or 1 of the followingapproaches and 1 of your own devising.• Tri-gram (or even quadrigram) models• Word similarity methods e.g., using Googlenews vectors or WordNet?• Combining n-gram methods with word similarity methods e.g., distributional smoothing?• Using a neural language model?It does not matter how well your method(s) perform. However, your methods should be clearlydescribed, any hyper-parameters (either fixed, varied or optimised) should be discussed and there shouldbe a clear comparison of the approaches with each other and the unigram and bigram baselines - bothfrom a practical and empirical perspective.You have been provided with the training and test data for this task in the labs. You may (andare expected to) use any of the code that you have developed throughout the labs. This includes codeprovided to you in the exercises or solutions. You may use any other resources to which you have access.You are encouraged to make use of one or more of WordNet, the Lin dependency thesaurus provided inNLTK and/or Word2Vec word embeddings. You may also download other resources from the Internetand make use of any Python libraries that you are familiar with.Your report should be in the style of an academic paper. It should include an introduction to theproblem and the methods you have implemented. It could include a brief discussion of related workin the area but the focus of the report must be your own practical work and you are not expected tocarry out a comprehensive literature review. You should discuss the hyper-parameter settings - boththose which you have decided to fix and any which you are investigating. You should discuss and justifythe method of evaluation. You should provide your results and compare them with the unigram andbigram baselines. You should also provide some analysis of errors - do the approaches make the same ordifferent mistakes and can you comment on the types or causes of errors being made? You should endwith your conclusions and areas for further work. You should also submit your code as an appendix.Your report (including figures and bibliography but not including code appendix) should be no longerthan 8 sides (3000 words of text plus figures and bibliography). Your code in the appendix should beclearly commented.Marks will not be awarded simply for how well your system does or for programming wizardry. Markswill be awarded for clearly evaluating possible solutions to the sentence completion challenge.2 Marking Criteria and RequirementsTable 1 shows the number of marks available for each requirement (Total = 60).Requirement Max mark Interpretationproblem outline 7 Does the introduction explain the task and the motivation for findingmethods which do well at this task?method 10 Is there a clear description of the proposed methods for tackling thetask? Do the proposed methods seem sensible? Novel or more interestingmethods may score highly here (if well-described) but methodswill not necessarily gain more marks simply by being more ambitious.hyper-parametersettings5 Within each proposed method, are there any hyper-parameter settingswhich are being fixed or explored? Are these clearly explained?evaluation 10 Is the method of evaluation stated, explained and justified? Areresults clearly presented (in a table and/or a graph!)?analysis 10 Is there an analysis of errors of the methods? Are there particulartypes of question which one or both methods do badly at?conclusion 3 Is there a sensible conclusion?further work 5 Are there sensible suggestions for further work to do in this area.These might include improvements to the method, other methods orother applications of the method.academic style 5 Is the report written in the style of a research paper? Are majorpoints backed up with references? Is the report well-written andwell-structured?code appendix 5 Is the code in the appendix clear and correct?Table 1: Breakdown of marksFor each requirement, the following scale will be used when deciding the number of marks awarded.85%-100% Outstanding. Demonstrates a thorough understanding and appreciation of the material withoutsignificant error or omission; evidence of extra study or creative thought70%-84% Excellent. Demonstrates a thorough understanding and appreciation of the material producing workwithout significant error or omission60%-69% Very good. Clear understanding demonstrated, substantially complete and correct. There may beminor gaps in knowledge/understanding. Evidence of independent thought50%-59% Reasonable knowledge and understanding of basic issues demonstrated.45%-49% Basic knowledge and understanding demonstrated with some appreciation of the issues involved.Gaps in knowledge and understanding; confusion over more complex material.40%-44% Significant issues neglected with little or no appreciation of the complexity of the problem.20%-39% Some correct or relevant material but significant issues neglected / sig. errors or misconceptions0%-19% Very little or nothing that is correct and relevantReferencesGeoffrey Zweig and Christopher Burges. 2011. The microsoft research sentence completion challenge. Technicalreport, Microsoft Research, December. ...

January 19, 2023 · 5 min · jiezi

关于算法:42889程序设计分析

Faculty of Engineering and Information TechnologySchool of Computer Science 42889 $XWXPQ 2022Assessment Task 1Individual programming project: Command-line calculatorDue 250DU202 2 at 11:5 9 pmThis project is worth 25% of the overall mark for this subject.ObjectivesThe purpose of this project is to demonstrate competence in the following skills:Program designArray and string manipulationCommand line argumentsCreating classes and methods inSwiftException handlingAutomated testingThese tasks reflect all the subject objectives.The reference i mplementation takes about 200 li nes of co de. As part of your subject wor kloadassessment, it is estimated this project will take 22.5 h ours to complete.Instructions3.Use "Product > Test" to test your functionality. ...

January 19, 2023 · 7 min · jiezi

关于算法:MATH5905统计分析

MATH5905 Term One 2022 Assignment One Statistical InferenceUniversity of New South WalesSchool of Mathematics and StatisticsMATH5905 Statistical InferenceTerm One 2022Assignment OneGiven: Friday 25 February 2022 Due date: Sunday 13 March 2022Instructions: This assignment is to be completed collaboratively by a group of at most 3students. The same mark will be awarded to each student within the group, unless I have goodreasons to believe that a group member did not contribute appropriately. This assignment mustbe submitted no later than 11:55 pm on Sunday, 13 March 2022. The first page of the submittedPDF should be this page. Only one of the group members should submit the PDF fileon Moodle, with the names of the other students in the group clearly indicated in the document.I/We declare that this assessment item is my/our own work, except where acknowledged, andhas not been submitted for academic credit elsewhere. I/We acknowledge that the assessor ofthis item may, for the purpose of assessing this item reproduce this assessment item and providea copy to another member of the University; and/or communicate a copy of this assessmentitem to a plagiarism checking service (which may then retain a copy of the assessment item onits database for the purpose of future plagiarism checking). I/We certify that I/We have readand understood the University Rules in respect of Student Academic Misconduct.Name Student No. Signature Date1MATH5905 Term One 2022 Assignment One Statistical InferenceProblem OneConsider a random vector with two components X and Y. Denote the cumulative distributionfunction (cdf) as FX,Y (x, y), and the marginal cdf as FX(x) and FY (y), respectively.i) Show, using first principles, thatFX(x) + FY (y) − 1 ≤ FX,Y (x, y) ≤pFX(x)FY (y)always holds.ii) Suppose that the X and Y are components of continuous random vector with a densityfX,Y (x, y) = cxy, 0 < y < x, 0 < x < 2 (and zero else). Here c is a normalizing constant.a) Show that c =12.b) Find the marginal density fX(x) and FX(x).c) Find the marginal density fY (y) and FY (y).d) Find the conditional density fY |X(y|x).e) Find the conditional expected value a(x) = E(Y |X = x).Make sure that you show your working and do not forget to always specify the support ofthe respective distribution.Problem TwoAt a critical stage, a fund manager has to make a decision about investing or not investing incertain company stock. He intends to apply a statistical decision theory approach to work outthe appropriate decision based on the potential long-term profitability of the investment. Heuses two independent advisory teams with teams of experts and each team should provide himwith an opinion about the profitability. Data X represents the number of teams recommendinginvesting in the stock (due, of course, to their belief in its profitability).If the investment is not made and the stock is not profitable, or when the investment ismade and the stock turns out profitable, nothing is lost. In the manager’s judgement, if thestock turns out to be not profitable and decision is made to invest in it, the loss is three timehigher than the cost of not investing when the stock turns out profitable.The two independent expert teams have a history of forecasting the profitability as follows. Ifa stock is profitable, each team will independently forecast profitability with probability 4/5(and no profitability with 1/5). On the other hand, if the stock is not profitable, then eachteam predicts profitability with probability 1/2. The fund manager will listen to both teamsand then make his decisions based on the data X.a) There are two possible actions in the action space A = {a0, a1} where action a0 is toinvest and action a1 is not to invest. There are two states of nature = {0, 1} where0 = 0 represents “profitable stock” and 1 = 1 represents “stock not profitable”. Definethe appropriate loss function L(, a) for this problem.b) Compute the probability mass function (pmf) for X under both states of nature.c) The complete list of all the non-randomized decisions rules D based on x is given by:2MATH5905 Term One 2022 Assignment One Statistical Inferenced1 d2 d3 d4 d5 d6 d7 d8x = 0 a0 a1 a0 a1 a0 a1 a0 a1x = 1 a0 a0 a1 a1 a0 a0 a1 a1x = 2 a0 a0 a0 a0 a1 a1 a1 a1For the set of non-randomized decision rules D compute the corresponding risk points.d) Find the minimax rule(s) among the non-randomized rules in D.e) Sketch the risk set of all randomized rules D generated by the set of rules in D. Youmight want to use R (or your favorite programming language) to make this sketch moreprecise.f) Suppose there are two decisions rules d and d′. The decision d strictly dominates d′ifR(, d) ≤ R(, d′) for all values of and R(, d) < (, d′) for at least one value . Hence,given a choice between d and d′ we would always prefer to use d. Any decision ruleswhich is strictly dominated by another decisions rule (as d′is in the above) is said to beinadmissible. Correspondingly, if a decision rule d is not strictly dominated by any otherdecision rule then it is admissible. Show on the risk plot the set of randomized decisionsrules that correspond to the fund manager’s admissible decision rules.g) Find the risk point of the minimax rule in the set of randomized decision rules D anddetermine its minimax risk. Compare the two minimax risks of the minimax decisionrule in D and in D. Comment.h) Define the minimax rule in the set D in terms of rules in D.i) For which prior on {1, 2} is the minimax rule in the set D also a Bayes rule?j) Prior to listening to the two teams, the fund manager believes that the stock will beprofitable with probability 1/2. Find the Bayes rule and the Bayes risk with respect tohis prior.k) For a small positive = 0.1, illustrate on the risk set the risk points of all rules whichare -minimax.Problem ThreeIn a Bayesian estimation problem, we sample n i.i.d. observations X = (X1, X2, . . . , Xn)from a population with conditional distribution of each single observation being the geometricdistributionfX1|(x|) = x(1 − ), x = 0, 1, 2, . . . ; 0 < < 1.The parameter is considered as random in the interval = (0, 1).i) If the prior on is given by () = 32, 0 < < 1, show that the posterior distributionh(|X = (x1, x2, . . . , xn)) is in the Beta family. Hence determine the Bayes estimator of withrespect to quadratic loss.Hint: For > 0 and > 0 the beta function B(, ) = R 10x−1(1 − x)−1dx satisfiesB(, ) = ()()(+) where () = R ∞0exp(−x)x−1dx. A Beta (, ) distributed randomvariable X has a density f(x) = 1B(,)x−1(1 − x)−1, 0 < x < 1, with E(X) = /( + ).3MATH5905 Term One 2022 Assignment One Statistical Inferenceii) Five observations form this distribution were observed: 2, 4, 7, 2, 3. Using zero-one loss,what is your decision when testing H0 : ≤ 0.80 against H1 : > 0.80. (You may usethe integrate function in R or another numerical integration routine from your favouriteprogramming package to answer the question.)Problem FourLet X1, X2, . . . , Xn be i.i.d. uniform in (0, ) and let the prior on be the Pareto prior given by () = −(+1), > . (Here > 0 and > 0 are assumed to be known constants). Showthat the Bayes estimator with respect to quadratic loss is given by Bayes = max(, x(n))n+n+−1.Justify all steps in the derivation. ...

January 18, 2023 · 6 min · jiezi

关于算法:分享回顾|新岁序开2023-和Jina-AI共同码梦

在保持凋谢合作精力、具备寰球影响力的 Jina AI 开源社区,每天都有来自世界各地的开发者来到这里,因为技术产生联结,因为联结产生共创。始终以来,咱们都为领有这样一个全球化、多元化和高速倒退的社区而感到骄傲和感谢!就在昨晚 20 点,Jina AI 社区举办了「NiceMeet You·兔年迎新面对面」流动,联结了 8 位合作伙伴,与 100 多位社区开发者、4000 多位观看直播的观众一起回顾咱们独特发明的 2022,并瞻望行将到来的 2023 年!再次感激大家的到来和反对,预祝大家兔年大吉、万事如意!! 本文将梳理汇总流动的精彩分享,供大家参考。 前“兔”无穷Jina AI 产品生态和社区倒退 - 回顾 2022 &  瞻望 2023 Jina AI 联结创始人兼 CTO 王楠博士 在 2022 年 1 月 9 号,咱们开源了 DocArray 的第一个版本。在看到了 AI 在 NLP、 CV 语音畛域突飞猛进之后,咱们置信多模态是将来十分重要的趋势。 DocArray 就是咱们针对这一趋势给出的答案,这也是咱们对于多模态 AI 的重要奉献。咱们心愿开发者在应用多模态数据的过程中能有这种技术,无感召就能够十分不便自若地去操作,去存储和解决多模态数据,迭代也十分快。去年年底咱们公布了DocArray v0.20.1,当然这离不开社区开发者的帮忙和反馈。 2 月,咱们公布了 Jina 3。Jina 3 反对 Kubernetes 云原生环境,助力开发者搭建云原生服务。之后,Jina 陆续反对各种云原生工具——Grafana、Promise、Sales、Open Telemetry。 3 月,咱们推出了 CLIP-as-service,正是因为咱们看到了 CLIP 的弱小利用,为了应答多模态的范式改革,拥抱生成式 AI 的热潮,咱们推出了该产品。 4 月,在 DALL·E 2 公布之后,咱们基于 Jina 构建了 DALL·E Flow,DALL·E Flow 的推出引爆了 AIGC 社区。紧接着在 6 月,咱们推出了 DiscoArt,这是咱们针对生成式 AI 给出的基于 Jina 搭建多模态 AI 零碎的答案。 ...

January 18, 2023 · 3 min · jiezi

关于算法:COMP30023-死锁的原理

COMP30023 Project 1Lock, Lock, ..., DeadlockOut date: March 14, 2022Due date: No later than 14:59 March 29, 2022 AEDTWeight: 15% of the final markBackgroundIn this project you will familiarise yourself with detection of deadlocks in a multi-process environment.Please note that you do not need to lock any files to implement this project.We strongly advise you to start working on the project as soon as possible and read the whole spec beforebeginning implementation.1 Detecting and breaking locksYou will be given a description of running processes and the files they need to execute, where each processis associated with two files. The first one is the file that the process has locked and the second one isthe file that it is waiting to lock. The goal of your program is to determine whether given the currentresource allocation and requests there is a deadlock or not. Please see Week 2 Lecture 2 on deadlocksfor more information.If there is no deadlock, you are asked to compute the minimum execution time required for all processesto finish given the following specification. If a process locked a file, it takes 1 time unit to operate onthis file and release it. If a process requested a file, after a process is given this file, it takes 1 timeunit to operate on this file and release it. Hence, any process takes at least 2 time units to finish. If kprocesses have requested the same file, it will take k time units for the processes to finish, where k ≥ 1.Processes that have locked or requested distinct files can operate in parallel. That is, if two processeshave requested two different files then it will take a total of 1 time unit for the processes to operate onthese files if both files are not locked by other processes.If there is a deadlock, you are asked to return process(es) that have to be terminated in order to resolvethe deadlock.2 Program SpecificationYour program will be invoked via the command line. It must be called detect and take the followingcommand line arguments. The arguments can be passed in any order but you can assume that theywill be passed exactly once.-f filename specifies the path to the file describing requests.-e is an optional parameter, which when provided requires your code to compute execution time. If thisoption is not given, your code should identify presence or absence of deadlocks and which processesneed to be terminated to resolve deadlock(s).-c is an optional parameter, which when provided invokes your file per process allocation from Section 4.The file specified by filename contains the processes and their locked and requested resources in thefollowing format.Each line of the file corresponds to a process and consists of a space-separated tuple:process-id space file-id space file-id1where the first file-id is the file that the process has locked and the second file-id is the file requested bythe process. You can assume that all process-ids will be distinct integers in the domain of [0, 232). Youcan assume that all file-ids will be integers in the domain of [0, 232).Example: ./detect -f resources.txtThe detection program is required to determine if there is a deadlock in the current resource allocation.For example resources.txt with the following information:0 1 31 2 7describes a system where process 0 has locked file 1 and is waiting for file 3 while process 1 has lockedfile 2 and waiting for file 7.If resources.txt has the following information:0 1 21 2 1then the system has processes 0 and 1, with locks on files 1 and 2, respectively. In addition, process 0requested file 2 while process 1 requested file 1. Hence, there is a deadlock.Each line (including the last) will be terminated with a LF (ASCII 0x0a) control character.We will not give malformed input (e.g., negative ids for processes and files, non-space delimiters, situationswhere more than one process locked the same file).3 Expected OutputIn order for us to verify that your code meets the specification, it should print to standard output (stderrwill be ignored) the following information. You should print each line of the expected output followedby new line.To get full marks you will be required to print the whole transcript as described below. However, youcan get marks for each task individually as long as your output for that specific task is correct. Forexample, you can get full marks for Task 1 and 2 without having implemented later tasks.Task 1. Systems statistics You are asked to print the total number of processes and files in thesystem (both locked and requested).Task 2. Execution time (No deadlock) You can assume that there is no deadlock in the fileallocation for this task only. You are asked to print minimum execution time required for all processesto finish given the specification in Section 1.Task 3. Deadlock detection Your program should print No deadlocks if there are no deadlocks, orDeadlock detected if there is at least one deadlock.Tasks 4,5. Breaking deadlocks If your program returns Deadlock detected, you are also asked toreturn a list of processes that need to be terminated to break the deadlock. You should print them ona separate line, separated by spaces. If there are many processes which can be terminated to break aparticular deadlock, choose the process with the smallest ID.You will need to print the minimum number of processes that need to be terminated to remove alldeadlocks. If there is more than one process that need to be terminated, separate them by space andprint them in ascending order, sorted by process ID.Sample output 1Given resources.txt with the following information:0 1 21 2 12On ./detect -f resources.txt your program should print:Processes 2\nFiles 2\nDeadlock detected\nTerminate 0\nSample output 2Given resources.txt with the following information:0 1 31 2 4On ./detect -e -f resources.txt your program should print:Processes 2\nFiles 4\nExecution time 2\nsince processes can proceed in parallel with each other, with each process taking 2 time units as each isoperating on 2 files sequentially.4 Challenge taskIf a deadlock was detected, you are asked to come up with a transcript that allocates files to processesin such a way that a deadlock is avoided. That is, you can assume that all resources are available andno files have been locked yet. Instead, the two file-ids associated with a process in the input file are twofiles required for the process to execute. A process can only execute if it obtains both files at the sametime. Once it obtains the files, it locks them and releases at the next time unit. Hence, a file cannot beallocated to more than one process at any given time. A naive way of allocating files to processes wouldbe to allocate both files to a process, then, once this process releases them (i.e., at the next time unit),proceed to allocating files to the next process. This would however lead to a slow execution that doesnot have any parallelism. Your task is instead to allocate files to separate processes at the same timewhile avoiding deadlocks.In order for us to evaluate whether your allocation avoids deadlocks, you are asked to print an allocationtranscript in the following format. If a process is allocated its two files, print on a separate linetime space process-id space file-id comma file-idThe order in which the file-ids appear above is up to you. You can assume that the process willautomatically release the files allocated to it at the next time unit, so you do not have to print anythingto release the files. You are also asked to print the total simulation time, i.e., the time when all processeshave been given all the files and released them. Time should start at 0, that is the first line of yourtranscript will have 0 as time.You will be required to explain how your algorithm is more efficient than naive sequential allocation ina short report.Sample output 3Given resources.txt with the following information:0 1 21 2 32 3 43 4 1./detect -f resources.txt -c could print:0 0 1,2\n0 2 3,4\n1 1 2,3\n1 3 4,1\nSimulation time 2\n3Note that with -c your program should not print the output required in Section 3.5 Marking CriteriaThe marks are broken down as follows:Task # and description Marks ...

January 18, 2023 · 13 min · jiezi

关于算法:MATH-170B解决办法

HOMEWORK 3 SOLUTIONS (MATH 170B, WINTER 2022)DUE DATE: SEE CANVASREVISION NUMBER: 3.0SUBMITTING HOMEWORK ON GRADESCOPE: For non-computer problems, create a PDF file of your work by whatever means you prefer(scanning handwritten work with your phone, or using LaTeX to typeset your mathematics, either is fine), and upload that PDF to Gradescope. Forcomputer problems, take a screen shot of both your MATLAB functions (the code you write) and the output they produce, and upload that PDF toGradescope.OUR HOMEWORK RULES ALWAYS APPLY: As discussed in detail on the syllabus, you are allowed (encouraged) to discuss homeworkproblems with other students in our class, but you must write up your own solutions yourself. You are not allowed to post these questions, or theirsolutions, on homework help websites (such as Chegg.com) or other websites.[Q1] (Section 6.4: Problem 6.4.7)(a) Determine all the values of a, b, c, d, e for which the following function is a cubicspline:fpxq “$&% apx′ 2q2 ` bpx′ 1q3, x P p′8, 1scpx′ 2q2, x P r1, 3sdpx′ 2q2 ` epx′ 3q3, x P r3,8s.(b) Determine the values of the parameters so that the cubic spline interpolates this data:x 0 1 4y 26 7 25(Hint: Just impose all the spline conditions.)Solution:(a) Denote S0pxq “ apx′2q2bpx′1q3, S1pxq “ cpx′2q2, S2pxq “ dpx′2q2epx′3q3.EnforceSi′1ptiq “ Siptiq, S 1i′1ptiq “ S 1iptiq and S2i′1ptiq “ S2i ptiqfor points t1 “ 1, t2 “ 3 and i “ 1, 2.Then we obtain the result a “ c “ d. For any a “ c “ d and arbitrary values of b, e,the function f is a cubic spline.(b) Add the equations of interpolation fp0q “ 26, fp1q “ 7, fp4q “ 25, we have4a` b “ 26a “ c “ d “ 74d` e “ 25Solve the above system we get the answer a “ 7, b “ ′2, c “ 7, d “ 7, e “ ′3.12 REFERENCES[Q2] (Section 6.4: Problem 6.4.11)(a) Determine the values of a, b, c so this is a cubic spline having knots 0, 1, 2:fpxq “"3` x′ 9x2, x P r0, 1sa bpx′ 1q cpx′ 1q2 ` dpx′ 1q3, x P r1, 2s(b) Determine d so that?20rf2pxqs2 dx is minimized.(c) Find d so that f2p2q “ 0; why is d different from d in part (b)?(Hint: The first part is just applying the spline conditions; the second part is first-quarter calculus,and the last part is again appling a spline condition.)Solution:(a) DenoteS0pxq “ 3` x′ 9x2S1pxq “ a bpx′ 1q cpx′ 1q2 ` dpx′ 1q3.ThenS 10pxq “ 1′ 18x S20pxq “ ′18S 11pxq “ b 2cpx′ 1q 3dpx′ 1q2 S21pxq “ 2c` 6dpx′ 1qFor f to be a cubic spline, we must haveS0p1q “ S1p1q ù? ′5 “ aandS 10p1q “ S 11p1q ù? ′17 “ bandS20p1q “ S21p1q ù? ′18 “ 2c ù? ′9 “ c.So f is a cubic spline when a “ ′5 , b “ ′17 , c “ ′9 , and d is any real number.(b) First, calculate? 2HOMEWORK 1 SOLUTIONS (MATH 170B, WINTER 2022)DUE DATE: SEE CANVASREVISION NUMBER: 1.0INSTRUCTOR: Prof. Michael HolstBOOKS:[1] D. Kincaid and W. Cheney. Numerical Analysis: Mathematics of Scientific Computing. Third. Providence, RI: American MathematicalSociety, 2017.MATERIAL COVERED BY HOMEWORK 1: This homework covers mainly material from lectures in weeks one and two, covering roughlythe following sections of [1]: 1.1, 1.2, 3.1, 3.2, 3.3, 3.4, 3.6.SUBMITTING HOMEWORK ON GRADESCOPE: For non-computer problems, create a PDF file of your work by whatever means you prefer(scanning handwritten work with your phone, or using LaTeX to typeset your mathematics, either is fine), and upload that PDF to Gradescope. Forcomputer problems, take a screen shot of both your MATLAB functions (the code you write) and the output they produce, and upload that PDF toGradescope.OUR HOMEWORK RULES ALWAYS APPLY: As discussed in detail on the syllabus, you are allowed (encouraged) to discuss homeworkproblems with other students in our class, but you must write up your own solutions yourself. You are not allowed to post these questions, or theirsolutions, on homework help websites (such as Chegg.com) or other websites.[Q1] (Section 1.1/1.2: Review: Taylor’s Theorem and Related; Similar to Exercise 1.1.5)Let fpxq “ cospxq.(1) Derive the Taylor series for fpxq at x “ 0. (Use summation notation.)(2) Write down the Taylor remainder for the series when truncating the series at n terms.(3) Find the min number of terms needed to compute fp1q with error ? 10′4.(Hint: This is all in Section 1.1, and in your Calculus book from your first quarter of calculus.)Solution:(1) f 1pxq “ ′sinx, f 2pxq “ ′cosx, f p3qpxq “ sinx, f p4qpxq “ cosx.so fpxq “ 1′ x2 ...

January 18, 2023 · 4 min · jiezi

关于算法:python算法学习记录冒泡排序

''''明天记录一下冒泡排序算法所谓排序无非把一些数字按肯定的规定进行排列,比方把【1,3,4,2,6,5,8】排列成【1,2,3,4,5,6,8】的模式,上面开始写代码'''#首先定义一个函数#参数间接传入一个列表def my_sort_(array): #对排序过程进行循环,次数为列表的长度 for i in range(len(array)): #对列表进行遍历,次数为列表长度减去i再减1 for j in range(0,len(array)-i-1): #这里咱们对array[j]和array[j+1]进行判断,并且创立一个temp变量 #为什么要创立一个temp变量呢,这里波及到变量的援用问题 #咱们假如array[0]-->1,array[1]-->2,如果咱们间接替换array[0]和array[1]的话, #在替换过程中会造成数据损失,因为在python中,变量名相似一种利用指针,它是通过地址来拜访 #数据的,对变量名赋值实际上是在更改变量名所代表的地址,例如 a=1, a=2,a代表的是不同的地址 #当咱们把a从新赋予2时,1就被垃圾收集掉了,所以为了保留数据,咱们须要从新把1赋予一个变量 # 所以咱们须要创立一个temp变量来保留数据 if array[j]>array[j+1]: temp = array[j] array[j] = array[j+1] array[j+1] = temp return array

January 18, 2023 · 1 min · jiezi

关于算法:python算法笔记变位词问题

变位词问题所谓的变位词是指两个词之间存在组成字母重新排列的问题,如“python” 和“nohtpy",当初咱们须要写出一个算法来判断两个词是否是变位词 '''定义一个函数,change_position'''def change_position(x,y): #该函数有两个参数,数据类型为string #首先咱们须要判断一下,两个参数的长度是否相等,如果不相等,间接能够判断不是变位词 if not len(x) == len(y): return False else: #else模块在两个词长度相等的状况下执行 #当长度雷同时,咱们去遍历x,y中的元素进行判断 #首先咱们须要先设置一个match_num,它是用来记录匹配胜利的数量 match_num = 0 for i in x: for j in y: #如果i和j相等的话,match_num就加一,而后打断二级循环,防止运算量的增大 if i == j: match_num+=1 break #如果match_num和x的长度相等就表明全副匹配,因而x和y是变位词 if match_num == len(x): return True else: return False

January 18, 2023 · 1 min · jiezi

关于算法:CS-4760-Operating-Systems

Project # 3 Due Date: March 17, 2022Semaphores and Message PassingPurposeThe goal of this homework is to become familiar with semaphores in Linux. It is a repetition of your last project with thepart that was handled by the bakery algorithm to be implemented by semaphores.You will again use multiple concurrent processes to write into a file at random times, solving the concurrency issues usingsemaphores for synchronization of processes. Your job is to create the environment such that two processes cannot writeinto the file simultaneously and yet, every process gets its turn to write into the file.TaskGenerate twenty processes using a master program, called master, and make them write into a file called cstest in theircurrent working directory. Needless to say that all processes will use the same working directory. Each child process willbe executed by an executable called slave. The message to be written into the file is:HH:MM:SS Queue nn File modified by process number xxwhere HH:MM:SS is the current system time, nn is the number the process picked when it entered its intention to write intothe file, xx is the process number as specified by the master program. The value of xx is between 1 and 20. This impliesthat the child process will be run by the commandslave xxThe critical resource is the file cstest which should be updated by a child under exclusive control access. This impliesthat each slave will have a critical section that will control access to the file to write into it.The main program masterWrite master that runs up to n slave processes at a time. Make sure that n never exceeds 20. Start master by typing thefollowing command:master -t ss nwhere ss is the maximum time in seconds (default 100 seconds) after which the process should terminate itself if notcompleted.Implement master as follows: ...

January 18, 2023 · 8 min · jiezi

关于算法:CSC373动态编程

CSC373Week 5: Dynamic Programming (contd)Network Flow (start)373W22 1Karan Singh, Nathan Wiebe*slides adapted from Nisarg ShahRecap373W22 2 Some more DP Traveling salesman problem (TSP) Start of network flow Problem statement Ford-Fulkerson algorithm Running time Correctness using max-flow, min-cutThis Lecture373W22 3 Network flow in polynomial time Edmonds-Karp algorithm (shortest augmenting path) Applications of network flow Bipartite matching & Hall’s theorem Edge-disjoint paths & Menger’s theorem Multiple sources/sinks Circulation networks Lower bounds on flows Survey design Image segmentationFord-Fulkerson Recap373W22 4 Define the residual graph of flow has the same vertices as For each edge e = (, ) in , has at most two edgeso Forward edge = (, ) with capacity ? We can send this much additional flow ono Reverse edge = (,) with capacity () The maximum “reverse” flow we can send is the maximum amount by which we canreduce flow on , which is ()o We only add each edge if its capacity > 0Ford-Fulkerson Recap373W22 5 Example!Flow Residual graphFord-Fulkerson Recap373W22 6MaxFlow():// initialize:Set = 0 for all in// while there is an - path in :While = FindPath(s, t,Residual(, ))!=None:= Augment(,)UpdateResidual(,)EndWhileReturnFord-Fulkerson Recap373W22 7 Running time: #Augmentations:o At every step, flow and capacities remain integerso For path in , bottleneck , > 0 implies bottleneck , ≥ 1o Each augmentation increases flow by at least 1o At most = ∑ leaving () augmentations Time for an augmentation:o has vertices and at most 2 edgeso Finding an - path in takes ( + ) time Total time: ( + ? )Edmonds-Karp Algorithm373W22 8 At every step, find the shortest path from to in , andaugment.MaxFlow():// initialize:Set = 0 for all in// Find shortest - path in & augment:While = BFS(s, t,Residual(, ))!=None:= Augment(,)UpdateResidual(,)EndWhileReturnMinimum number of edgesProof373W22 9 () = shortest distance of from in residual graph Lemma 1: During the execution of the algorithm, () doesnot decrease for any . Proof: Suppose augmentation → decreases () for some Choose the with the smallest in ′o Say = in ′, so ≥ + 1 in Look at node just before on a shortest path → in ′o = ? 1 in ′o () didn’t decrease, so ≤ ? 1 in () = shortest distance of from in residual graph Lemma 1: During the execution of the algorithm, () doesnot decrease for any .? In , (, ) must be missing? We must have added (, ) byselecting (,) in augmenting path? But is a shortest path, so it cannothave edge , with >Proof373W22 11 Call edge (, ) critical in an augmentation step if It’s part of the augmenting path and its capacity is equal to bottleneck(, ) Augmentation step removes and adds (if missing) Lemma 2: Between any two steps in which (, ) is critical,() increases by at least 2 Proof of Edmonds-Karp running time Each () can go from 0 to (Lemma 1) So, each edge (, ) can be critical at most /2 times (Lemma 2) So, there can be at most ? /2 augmentation steps Each augmentation takes () time to perform Hence, 2 operations in total!Proof373W22 12 Lemma 2: Between any two steps in which (, ) is critical,() increases by at least 2 Proof: Suppose (, ) was critical ino So, the augmentation step must have removed it Let = () ino Because , is part of a shortest path, = + 1 in For (, ) to be critical again, it must be added back at some pointo Suppose ′ → ′′ steps adds it backo Augmenting path in must have selected (,)o In ′: = + 1 ≥ + 1 + 1 = + 2Lemma 1 onEdmonds-Karp Proof Overview373W22 13 Note: Some graphs require () augmentation steps But we may be able to reduce the time to run each augmentationstep Two algorithms use this idea to reduce run time Dinitz’s algorithm [1970] ?(2) Sleator–Tarjan algorithm [1983] ?( log)o Using the dynamic trees data structure373W22 14Network Flow Applications373W22 15Rail network connecting Soviet Union with Eastern European countries(Tolstoǐ 1930s)373W22 16Rail network connecting Soviet Union with Eastern European countries(Tolstoǐ 1930s)Min-cutIntegrality Theorem373W22 17 Before we look at applications, we need the following special property of themax-flow computed by Ford-Fulkerson and its variants Observation: If edge capacities are integers, then the max-flow computed by Ford-Fulkerson and its variantsare also integral (i.e., the flow on each edge is an integer). Easy to check that each augmentation step preserves integral flowBipartite Matching373W22 18 Problem Given a bipartite graph = ( ∪ ,), find a maximum cardinality matching We do not know any efficient greedy or dynamic programming algorithm for thisproblem. But it can be reduced to max-flow.Bipartite Matching373W22 19 Create a directed flow graph where we… Add a source node and target node Add edges, all of capacity 1:o → for each ∈ , → for each ∈o → for each , ∈ ...

January 18, 2023 · 5 min · jiezi

关于算法:ECS784U题型解答

Coursework 1 specification for 2022 Data Analytics ECS648U/ ECS784U/ ECS784PRevised on 01/02/2022 by Dr Anthony Constantinou Important Dates Release date: Thursday 3rd February 2022. Submission deadline: Monday 14th March 2022 at 10:00 AM. Late submission deadline (cumulative penalty applies): Within 7 days after deadline. General information: i. Some students will sometimes upload their coursework and not hit the submit button.Make sure you fully complete the submission process.ii. A penalty will be applied automatically by the system for late submissions.a. Lecturers cannot remove the penalty!b. Penalties can only be challenged via submission of an ExtenuatingCircumstances (EC) form which can be found on your Student Support page.All the information you need to know is on that page, including how to submitan EC claim along with the deadline dates and full guidelines.c. If you submit an EC form, your case will be reviewed by a panel. When thepanel reaches a decision, they will inform both you and the Module Organiser.d. If you miss both the submission deadline and the late submission deadline, youwill automatically receive a score of 0. Extensions can only be granted throughapproval of an EC claim.iii. Submissions via e-mail are not accepted.iv. It is recommended by the School that we set the deadline during a weekday at 10:00AM. Do not wait until the very last moment to submit the coursework.v. For more details on submission regulations, please refer to your relevant handbook. ...

January 18, 2023 · 4 min · jiezi

关于算法:算法训练营数值计算篇

1. 将一个指定整数值等分成指定的数量,最终返回这个能被等分的整数值 /** * @param {Number} * @return {Number} */ function intervalHandle (num, num_interval) { if (indexOfHandle(num, num_interval)) { return num } else { for (var i = 0; i <= num_interval; i++) { var num_new = num num_new += i; if (indexOfHandle(num_new, num_interval)) { return num_new } } } function indexOfHandle(x, y) { return String((x / y)).indexOf('.') === -1 } } intervalHandle(1999, 10) // => 2000 // intervalHandle(给定的值, 要等分的个数) // 利用场景: 图表x/y轴计算最大值和距离值2. 判断一个数是不是质数/素数概念: ...

January 16, 2023 · 2 min · jiezi

关于算法:杨辉三角的5个特性一个比一个牛皮

作者:小傅哥 博客:https://bugstack.cn 积淀、分享、成长,让本人和别人都能有所播种!一、前言杨辉三角的历史杨辉三角依照杨辉于1261年所编写的《详解九章算法》一书,外面有一张图片,介绍此种算法来自于另外一个数学家贾宪所编写的《释锁算书》一书,但这本书早已失传无从考据。但能够必定的是这一图形的发现我国不迟于1200年左右。在欧洲,这图形称为"巴斯加(Pascal)三角"。因为个别都认为这是巴斯加在1654年创造的。其实在巴斯加之前曾经有许多人遍及过,最早是德国人阿匹纳斯(Pertrus APianus),他已经把这个图形刻在1527年著的一本算术书封面上。但无论如何,杨辉三角的发现,在我国比在欧洲至多要早300年光景。 此外杨辉三角原来的名字也不是三角,而是叫做开方作法根源,起初也有人称为乘法求廉图。因为这些名称切实太古奥了些,所以起初简称为“三角”。 在小傅哥学习杨辉三角的过程中,找到了一本大数学家华罗庚的PDF[《从杨辉三角谈起 - 华罗庚》]()。—— 这些数学真的十分重要,每每映射到程序中都是一段把for循环优化成算法的体现,进步执行效率。 二、杨辉三角结构在开始分享杨辉三角的个性和代码实现前,咱们先来理解下杨辉三角的构造结构。 杨辉三角的构造和法则非常简单,除去每次两边的1,两头的数字都是下面两个数字的和。如图示意的三角区域。但也就是如此简略的构造,却有着诸多的数学逻辑体现。包含咱们计算的二项式、N选X的种数还有斐波那契数列等,都能够在杨辉三角中体现进去。接下来咱们就来看看这些个性。 三、杨辉三角个性为了不便学习杨辉三角的数学逻辑个性,咱们把它按左对齐形式进行排列。 [1][1,1][1,2,1][1,3,3,1][1,4,6,4,1][1,5,10,10,5,1][1,6,15,20,15,6,1][1,7,21,35,35,21,7,1][1,8,28,56,70,56,28,8,1]接下来咱们就以这组杨辉三角数列,来展现它的数学逻辑个性。对于杨辉三角的Java代码放已到下文中,读者能够查阅。 1. 二项式开展大家在上学阶段肯定学习过二项式开展,例如:(x+y)^2 = x^2 + 2xy + y^2 其实这个开展的数学逻辑在杨辉三角中能够十分好的展现进去。 任意一个二项式开展后的数字乘积,都能够映射到杨辉三角对应的中的数字。二项式开展公式是用来计算给定二项式的指数幂的展开式的公式。对于给定的二项式 (x + y)n,二项式开展公式为:(x + y)^n = x^n + nx^{n-1}y + n(n-1)x^{n-2}y^2 + ... + y^n 这个公式也正好合乎杨辉三角的数字值。2. 组合数组合数是数学中定义的一种数学概念,用于计算有多少种抉择能够从一组物品中抉择出若干的物品。比方你早上有5种水果能够吃,但你吃不了那么多,让你5种水果当选2个,看看有多少种抉择。通过应用公式 c(n,k) = n!/k!(n-k)! 能够计算出,5选2有10种抉择。 那么这样一个计算也是能够体现在杨辉三角中的。 5选2,在杨辉三角中能够找到第5行的第2列,后果是10。依照这个法则,5选3=10、5选4=53. 斐波那契数列斐波那契数列呈现在印度数学中,与梵文韵律无关。在梵语诗歌传统中,人们对列举所有持续时间为 2 单位的长 (L) 音节与 1 单位持续时间的短 (S) 音节并列的模式很感兴趣。对于更多斐波那契更多常识能够浏览小傅哥的:《程序员数学:斐波那契》—— 为什么不能用斐波那契散列,做数据库路由算法? 斐波那契数列能够由递归关系定义:F0 = 0,F1 = 1,Fn = Fn-1 + Fn-2 F0F1F2F3F4F5F6F7F8F90112358132134而这样一个有法则的斐波那契数列在杨辉三角中也是有所体现的。 ...

January 13, 2023 · 2 min · jiezi

关于算法:嘿Jina-帮我画一幅高山流水图

本我的项目将 Whisper 与 Stable Diffusion 模型联合,能够间接实现语音生成图像的工作。用户能够语音输入一个短句,Whisper 会主动将语音转化为文本,接着,Stable Diffusion 会依据文本生成图像。本我的项目基于 Jina AI MLOps 平台搭建,通过应用 DocArray 逾越了不同数据类型之间的鸿沟,缩小了利用的数据传输老本。同时应用 Jina 搭建了一个云原生的基于微服务的 Pipeline,并且很容易就能部署到 Kubernetes 零碎中。 咱们都习惯了用 Siri、天猫精灵等智能语音助手来设置闹钟,播报天气,甚至它也会给咱们讲一些冷笑话。然而怎样才能更进一步呢?咱们怎样才能用本人的声音作为桥梁,和世界以及机器进行更加深刻、乏味的交互呢?目前的智能语音助手都是基于单模态的,即输出咱们的声音会输入它们的声音,与此同时,智能语音助手还会执行咱们的指令。这种单模态的工作模式就像是钢铁侠的 Mark I。尽管对于现有的工作,智能语音助手曾经实现得很好了,然而随着技术的一直变革,咱们冀望它能有更多的翻新。将 AI 技术赋能于语音识别系统,能够使得机器生成精美的画面,这就像是为 Alexa(亚马逊旗下的智能语音助手)拆卸上激光炮和火箭靴。咱们也能够借此实现更加简单的利用。不同于单模态的智能语音助手 Alexa、Siri,通过 Jina,咱们将关上多模态世界的大门。咱们能够利用文本生成图像,语音生成视频,甚至是任何一种模态信息生成(或者检索)另一种模态信息。与此同时,咱们不须要成为钢铁侠这样的蠢才,甚至无需领有浩克一样的智力,仅仅应用 90 行代码就能使魔法变为事实。咱们能够利用云原生的微服务框架实现跨模态转换工作,并将其部署在 Kubernetes 上。初步调研过来的几年里,人工智能技术呈爆发式倒退,咱们的钻研也从单模态模型(例如,用于文本的 Transformers,用于图像的 Big Image Transfer)迅速转向能够同时解决不同状态数据的多模态模型。遗憾的是,即便咱们的模型曾经转向多模态,这也仍然过期了。就在往年,咱们发现文本生成图像的工具急剧增长,例如 DiscoArt, DALL-E 2 和 Stable Diffusion。还有一些其余的模型甚至能够实现文本生成视频,图像生成 3D 模型的工作。Stable Diffusion 能够用来生成图像(咱们曾经用它生成了以下图像): 美队骑摩托的照片! 钢铁侠和Luke Skywalker跳舞的照片! 用活泼的色调,Artstation的风行趋势画一张蜘蛛侠在纽约上空飞檐走壁的4K数字插画。当初热门的不仅是多模态的文本图像生成,就在几周前,OpenAI 公布了一个主动语音识别系统 Whisper。在解决口音、背景噪声以及技术术语方面,Whisper简直达到了人类的水准。本文将 Whisper 与 Stable Diffusion 联合,能够间接实现语音生成图像的工作。用户能够语音输入一个短句,Whisper 会主动将语音转化为文本,接着,Stable Diffusion 会依据文本生成图像。现有解决方案语音生成图像并不是一个新的概念,许多学者曾经写过相干的论文: S2IGAN: Speech-to-Image Generation via Adversarial LearningDirect Speech-to-Image TranslationUsing AI to Generate Art - A Voice-Enabled Art Generation ToolBuilt with AssemblyAI - Real-time Speech-to-Image Generation与以上计划不同的是,咱们的示例基于最前沿的模型,并且齐全可扩大。咱们的应用程序是利用微服务架构搭建的,非常容易就能够部署到 Kubernetes。更重要的是,相比于上述的解决方案,咱们须要的代码量更小。要害挑战当思考能够用最新的多模态模型搭建什么时,你的设想可能会天马行空,然而理论的搭建不同于设想,存在几个关键问题: ...

January 12, 2023 · 2 min · jiezi

关于算法:AIGC-很火想微调个自己的模型试试看不是卖课的

去年,咱们公布过一篇对于 DreamBooth 编程马拉松的流动告诉,取得了寰球社区的宽泛关注和参加,中国社区的成员们也对这个流动有十分高的激情。同时咱们也收到了后盾留言反馈说参加流动须要应用的 Google Colab 等工具无奈稳固拜访。通过与数据迷信开源社区——「和鲸社区」的单干,咱们胜利的将本次「DreamBooth 编程马拉松」进行了本地化,并再次邀请你参加! 请留神,咱们与和鲸社区的单干指标是为中国社区成员提供一个微调和上传模型的渠道,本次编程马拉松的截止工夫和寰球参与方没有任何变动,因而间隔流动的截止工夫还有十天,请尽快加入!(*小编亲测,一个小时左右就能够搞定了) 被题目吸引进来的敌人,从这里开始看你想不想让事实中的物体,在图片中以各种形式展示?通过 DreamBooth,就能够做到!怎么做呢?1) 把冰箱门关上 2) 把大象装进去 3) 把冰箱门盖上(对,就是这么简略!) 通过 DreamBooth 技术,你能够让文本生成图片的大模型了解新的概念,比方你的宠物、喜爱的美食或者风光。比方,你能够喂给 AI 本人的狗狗的照片,而后就能够用模型生成狗狗在睡觉、游泳、理发等各种图片: 你也能够给本人爱车更换色彩,以及给本人的「网红」狗狗生成鬼畜素材: 图片起源: DreamBooth 官网 想试试看?心动不如口头在 Hugging Face,咱们深信 AI 技术能够惠及每个人,通过这次编程马拉松流动,不仅仅是从业者,咱们心愿让每个人都能体验并应用到人工智能技术,以取得灵感和想法。 为了筹备此次本地化的编程马拉松流动,咱们提供了中文的训练代码、「和鲸社区」为咱们提供了算力和平台反对,你只须要筹备一些图片 (确认本人有使用权),即可来参加咱们的流动,没有技术背景也能够参加! 真的,只需筹备一些图片就行了请确保抉择本人有使用权的图片,本次流动分为以下几个主题 (theme): 动物 (animal): 应用此主题生成你的宠物或青睐的动物在雅典卫城玩耍、在游泳或在太空中航行的图像迷信 (science): 应用此主题生成星系、蛋白质或任何自然科学和医学畛域里超赞的合成图像食物 (food): 应用此主题在你最喜爱的美味佳肴图像上微调你本人的 Stable Diffusion风光 (landscape): 应用此主题生成你最喜爱的山脉、湖泊或花园的漂亮风光图像通用 (wildcard): 此主题有限定的类别,你能够为抉择的任何类别创立 Stable Diffusion 模型还有各种奖品寰球社区奖品咱们将为每个主题颁发 3 类奖项,获奖者排名由 Hugging Face 排行榜上喜爱 (like) 最多的模型决定。 第一名获奖者: HuggingFace 专业版订阅 1 年或 HuggingFace 商品店 100 美元代金券第二名获奖者: 图书《NLP with Transformer》一本 (transformersbook.com) 或 HuggingFace 商品店的 50 美元代金券第三名获奖者: 1 个月的 HuggingFace 专业版订阅或 HuggingFace 商店的 15 美元代金券阳光普照奖: 只有胜利提交模型到 Hugging Face 平台,即可取得比赛参加证书和鲸社区奖品咱们会为在和鲸社区参加较量的参赛者额定提供礼物 (感激和鲸社区资助 )。 ...

January 11, 2023 · 1 min · jiezi

关于算法:Raft算法

什么是RaftRAFT协定是一种共识算法(consensus algorithm)。什么是共识算法,说白了也就是大多数成员达成统一的算法。那对于大多数有定量吗?有,大于等于N/2+1就是大多数,也就是多余半数的成员达成统一。 共识算法的典型代表是Paxos,而因为其不仅难以了解,更难以实现,所以衍生出了很多基于Paxos的算法,Raft就是其中之一,提供了一种更易懂、且便于工程实际的算法。 Raft有什么作用为了进步零碎的可用性,零碎设计时会引入备份(避免单点故障导致不可用)。比方零碎存储,会有一个主存储和N个备存储(多数据正本),随之产生了一个新的问题,零碎怎么保障主存储了备存储的数据统一(多正本之间数据一致性)? 一致性:一致性就是数据保持一致,在分布式系统中,能够了解为多个节点中数据的值是统一的。能够将一个具备强一致性的分布式系统当成一个整体,应用层能够疏忽底层多正本之间数据同步的问题。 Raft就是保障一致性的一种共识算法。 Raft算法介绍Raft算法基于状态复制机(Replicated State Machine),状态机将客户端的操作命令(command) 转换成日志(log),经各状态机依照程序解决后,apply到状态机中(state )。 依据状态机的运行逻辑,要保障个节点之间的state最终统一,也就是保障个节点的日志正本统一,其余节点依照程序解决日志后,使得集群内状态统一。 Raft就是用来治理日志正本(replicated log)的算法。Raft首先会选举出一个Leader,用于治理replicated log,Leader从客户端接管申请,解决成日志(log),并把日志同步给其余节点,而且会通知其余节点什么时候能够平安的apply 日志到状态机中。 Raft算法要保障了如下个性 选举平安:在一个term(上面有介绍),最多一个Leader能够被选举(或者没有选举进去Leader)。Leader 只容许日志条目减少:Leader节点永远不会笼罩或者删除本人的日志条目。只会新增新的日志条目。日志匹配:两条日志条目标term和index属性雷同,那么之前的日志条目信息也雷同。Leader完整性:如果在一个term中,一个日志条目被commited,在高版本term中的Leader肯定会用用这条被commited的日志条目。也就是说commited后的日志条目在集群中不会失落。状态机平安:一个节点的某index地位applied日志条目到状态机,不会存在其余节点将对应节点不同条目标日志apply到状态机。由此Raft算法拆分出了三个绝对独立的子问题 选主 leader election,Leader不存在或者Leader宕机的状况下须要抉择出一个Leader。日志复制 log replication,Leader将本人的日志同步给集群中其余节点。安全性 Safety:次要保障状态机平安个性,前面章节会具体介绍。选主 leader electionRaft集群中节点角色有以下三种: Leader: 所有申请解决节点。申请写入本地日志后同步集群其余节点。Follower:同步Leader节点日志,转发客户端申请给Leader节点。Candidate:在timeout实际内没有接管到Leader节点的心跳申请,认为Leader节点宕机,转换角色状态为Candidate,开始leader election,直到选主完结。任期 term 每当candidate触发leader election时都会减少term。term编号枯燥递增。每个节点都会保留一个以后任期term,通信时会带上这个term。 接下来咱们看下各角色之间的转换图 如何成为Follower 启动时节点默认为Follower。Candidate收到新Leader的RPC。所有节点,收的的申请(request)或者响应(response)中的term>currentTerm,变为Follower。如何成为Candidate Follower节点在timeout工夫内没有收到Leader节点的心跳申请且没有投票给Candidate。Candidate节点在timeout周期内,没有取得大多数选票,会维持Candidate角色。如何成为Leader Candidate节点在选举周期内取得集群内大多数选票,变为Leader。上面咱们来演示下常见的Leader election场景:选举胜利和选举失败。 Candidate节点获取其余节点的投票,通过RequestVote RPC,接口详情见下图。 投票规定: 每个term,各节点能够投一票,通过votedFor属性标识是否在本term内投票过。Candidate首先会给本人投一票。Follower没有投票给其余节点过,投票申请中的term>=节点以后term,且投票申请中的日志index要>=以后节点最新的日志条目index,满足以上条件的投票申请 采取先到先得的形式响应对应的Candidate。选举胜利:集群初始启动 模仿场景,集群共有5个节点S1~S5,刚开始启动时节点角色都为Follower,圈内数字标识term,刚启动时term为1,外圈灰色局部示意残余超时工夫。 S3节点超时,节点变为Candidate,开启一轮leader election。 S3的term+1变为2,S3首先投本人一票,并行的向集群中其余节点发送投票申请。 集群中的节点收到投票申请后,响应, 图片中带十字图标示意投票给申请的Candidate节点。 收到投票后果后的S3成为了Leader,选举胜利 选举失败场景:多节点同时开启leader election S3、S2节点宕机,S5和S4节点同时超时开启新一轮的leader election。 S4、S5都投给本人一票,S1的投票依据先到先得准则投给了S4,S4失去了两票< (5/2+1=3),不满足大多数准则,S4不能胜利变更为Leader。 期待S4选举超时,开启下一轮的leader election, ...

January 11, 2023 · 1 min · jiezi

关于算法:走进AI图像生成核心技术-Diffusion

编者按:2022年,Diffusion model成为图像生成畛域的重要发现,推动了AI绘画利用的爆发式倒退。Diffusion模型相较于其余的图像生成模型,在所需数据更少的背景下,图像生成成果有显著晋升。援用本期IDP Inspiration,咱们将和大家一起走进Diffusion的发展史。援用以下是译文,Enjoy!作者 | Kyle Wiggers 编译 | 岳扬 随着技术的提高,人工智能发明的艺术保真度失去了大大加强,文转图人工智能在往年暴发了。只管像Stable Diffusion和OpenAI的DALL-E 2这样的零碎存在许多争议,但包含DeviantArt和Canva在内的很多平台曾经采纳它们来制作创意工具,实现品牌的个性化,甚至创意新产品。 但这些零碎的核心技术 - Diffusion - 的能力远远不止生成艺术作品,它还被一些钻研小组用来制作音乐,合成DNA序列,甚至用于研制新药。 那么,到底什么是Diffusion,为什么它与以前的技术水平相比有如此大的飞跃?咱们须要来理解一下Diffusion的起源,以及它是如何随着工夫的推移而倒退成明天这样有影响力的。Diffusion的故事还没有完结——每个月都会呈现技术的改良,尤其过来一两年呈现了显著的提高。 Diffusion的诞生你或者还记得几年前爆火的deepfaking——这些App将人们的肖像插入现有的图像和视频中,发明出看起来很实在的换脸视频。利用人工智能,这些App会将一个人的脸,或者在某些状况下,他们的整个身材插入到某个场景中,往往可能产生足够的说服力,骗过大多数人。 这App大多依附一种叫做生成反抗网络的人工智能技术,简称GANs。GANs由两局部组成:一个从随机数据中产生合成内容(如图像)的生成器和一个试图辨别合成内容和训练数据集中的实在内容的鉴别器。生成器和鉴别器互相配合进步生成或鉴别能力,直到鉴别器无奈从合成的例子中分辨出实在的例子,此时其准确率曾经高于预期的50%。 哈利-波特和霍格沃茨的沙雕,由Stable Diffusion生成。图片起源:Stability AI 好的GAN能够创立很多真切的图片,例如虚构的公寓楼照片[1]。Nvidia几年前开发的StyleGAN,通过学习面部姿态、雀斑和头发等属性,能够生成虚构人物的高分辨率头像。除了生成图像之外,GANs还被利用于构建3D建模空间和绘制矢量草图[2],输入视频片段[3]以及语音[4],甚至还能利用乐器演奏样本生成歌曲。 不过,在实践中,GANs因为其构造而存在一些缺点。生成器和鉴别器的同时训练自身就是非常不稳固的。有时生成器会 “解体”,输入许多看起来很类似的样本。GANs还须要大量的数据和计算能力来运行和训练,这使得它们难以进行扩大。 Diffusion是如何工作的Diffusion的灵感来自于物理学——物理学中物质从高浓度区域向低浓度区域挪动的过程,就像糖块在咖啡中的溶解。咖啡中的糖粒最后集中在液体的顶部,但逐步变得扩散。 Diffusion特地借用了非均衡热力学中的扩散,该过程随着工夫的推移减少了零碎的熵(或随机性)。比方气体最终会通过随机静止扩散开来,平均地充斥整个空间。同样,像图像这样的数据也能够通过随机增加噪声而转变为均匀分布。 Diffusion通过增加乐音缓缓地毁坏数据的构造,直到除了乐音什么都不剩。 在物理学中,扩散是自发的和不可逆的——扩散到咖啡中的糖不能复原到立方体的模式。但机器学习中的扩散零碎旨在学习一种 “反向扩散” 过程来复原被毁坏的数据,取得从噪声中复原数据的能力。 Diffusion曾经存在了近十年,然而OpenAI最近的一项翻新,即CLIP(Contrastive Language-Image Pre-Training的简称)使它们在日常利用中更加实用。CLIP对数据(例如图像)进行分类,依据它在给定的文本提醒下被分类成某一类的可能性(例如:“花丛中的狗素描画”),对扩散过程的每一步进行“评分”。 在最开始的时候,会给数据一个非常低的CLIP分数,因为它大部分是噪声。但随着Diffusion从噪声中重建数据,它缓缓地靠近于文本提醒。能够用一个雕刻大理石的例子,就像一个雕刻巨匠通知一个老手在哪里雕刻一样,CLIP疏导Diffusion生成一个能给出更高分数的图像。 OpenAI将CLIP与图像生成零碎DALL-E一起推出。从那之后,又推出了DALL-E的后继者DALL-E 2,以及诞生了像Stable Diffusion这样的开源替代品。 Diffusion能做什么?那么,CLIP疏导的Diffusion能做什么?正如后面所提到的,它们在生成艺术作品方面相当杰出,从真切的艺术作品到素描、油画等,简直能够模拟任何艺术家的格调。事实上,有证据表明,它们会有针对性地反刍它们的一些训练数据。 但这些模型的天才(只管可能有争议)并没有到此为止。 钻研人员还尝试应用疏导式Diffusion来创作新音乐。Harmonai[5]是一个失去 Stability AI[6] 投资的公司,它公布了一个基于Diffusion的模型,通过对数百小时现有歌曲进行训练,能够输入音乐片段。最近,开发者Seth Forsgren和Hayk Martiros创立了一个被称为Riffusion的业余我的项目,该我的项目应用Diffusion奇妙地对音频的光谱图进行训练,以生成新的音乐。 除开音乐畛域之外,一些实验室正试图将Diffusion利用于生物医学,心愿能发现新的疾病医治办法。正如《 MIT Tech Review》本月早些时候报道的那样[7],守业公司Generate Biomedicines和华盛顿大学的一个团队训练了一个基于Diffusion的模型,能够进行具备特定属性和性能的蛋白质设计。 这些模型以不同的形式工作。Generate Biomedicines公司通过解开形成蛋白质的氨基酸链来减少噪声,而后在钻研人员指定的约束条件领导下,将随机链放在一起造成一个新的蛋白质。另一方面,华盛顿大学的模型从一个凌乱的构造开始,并应用一个独立的AI零碎来提供蛋白质碎片如何组合的信息来预测蛋白质构造。 他们曾经获得了一些成绩,华盛顿大学小组设计的模型找到了一种可能附着在甲状旁腺激素(管制血液中钙含量的激素)上的蛋白质,比现有药物更好。           图片起源:PASIEKA/SCIENCE PHOTO LIBRARY/Getty Images 同时,在OpenBioML[8],这是一个由Stability AI反对的我的项目,其将基于机器学习的办法引入生物化学的工作中,钻研人员开发了一个名为DNA-Diffusion的零碎,它可能生成细胞类型特异的调节性DNA序列(影响生物体内特定基因表白的核酸分子段)。如果所有按计划进行,DNA-Diffusion将通过文本指令生成调节性DNA序列,比方 “一个激活基因在X型细胞中达到最大表白程度的DNA序列” 和 “一个可能在肝脏和心脏中激活基因,但不在大脑中激活的DNA序列”。 Diffusion的将来可能是什么?所有皆有可能。当初钻研人员曾经将其利用于生成视频[9]、压缩图像[10]和合成语音[11]。这并不是说Diffusion最终不会被更无效、性能更强的机器学习技术所取代,就像GANs被Diffusion取代一样。但它领有明天的辉煌是有起因的,Diffusion如果不是多功能的,那就什么都不是。 参考资料 https://syncedreview.com/2019...https://venturebeat.com/2019/...https://venturebeat.com/2019/...https://venturebeat.com/2019/...https://www.harmonai.org/https://stability.ai/https://www.technologyreview....https://techcrunch.com/2022/1...https://arxiv.org/pdf/2204.03...https://arstechnica.com/infor...https://arxiv.org/abs/2204.09934

January 10, 2023 · 1 min · jiezi

关于算法:如何定义算法10分钟带你弄懂算法的基本概念

算法是指实现一个工作所须要的具体步骤和办法。也就是说给定初始状态或输出数据,通过计算机程序的无限次运算,可能得出所要求或冀望的终止状态或输入数据。 编程界的“Pascal 之父”Nicklaus Wirth 有一句人尽皆知的名言:“算法+数据结构=程序”。(Algorithm+Data Structures=Programs),可见算法对程序的重要性。 本文从算法的根本定义登程,具体解读了算法的倒退历程、次要特色、掂量指标和算法设计的根本办法,供大家学习参考。 1.算法的根本定义 百科百科对算法的定义是:算法(Algorithm)是指解题计划的精确而残缺的形容,是一系列解决问题的清晰指令,算法代表着用零碎的办法形容解决问题的策略机制。也就是说,可能对肯定标准的输出,在无限工夫内取得所要求的输入。 一句话概括一下,算法就是解决问题的操作步骤。 2.算法的倒退历程 在我国现代,算法被称为“演算法”,对于算法的起源最早能够追溯到我国现代公元前 1 世纪的《周髀算经》,是算经的十书之一,原名《周髀》,次要论述现代中国的盖天说和四分历法。在唐朝的时候,此书被定为国子监算科的教材之一,并改名为《周髀算经》。《周髀算经》中记录了勾股定理、开平方问题、等差级数等问题,其中用到了相当简单的分数算法和开平方算法等。在随后的倒退中,呈现了割圆术、秦九昭算法和残余定理等一些经典算法。 在东方,算法(algorithm)一词最早来源于 9 世纪波斯数学家花拉子米(花拉子米是代数与算术的创建人,被誉为“代数之父”,所著《代数学》一书,最早给出了一次和二次方程的个别解法),花拉子米的拉丁文译名是“Algoritmi”,英文对“算法”原译为“algorism”,意思是花拉子米的运算法令,指的是用阿拉伯数字进行算术运算的过程,在 18 世纪演变为“algorithm”。 阿拉伯数学家花拉子米 世界上第一个算法 公元前 300 年,“几何之父”欧几里得提出了人类史上第一个算法——欧几里得算法,又称辗转相除法,是求最大公约数的一种办法。它的具体做法是: 用较大数除以较小数,再用呈现的余数(第余数)去除除数,再用呈现的余数(第二余数)去除第一余数,如此重复,直到最初余数是 0 为止。如果是求两个数的最大公约数,那么最初的除数就是这两个数的最大公约数。 辗转相除法举例:求 10,25 的最大公约数:25/10=2……510/5=2……0所以 10,25 的最大公约数为 5 辗转相除法代码实现: int gcd(a, b)[ return b == 0 ? a : gcd(b, a % b); }//当余数为0时,最大公约数就是a,否则持续往下递归世界上第一个算法程序"If I should see you,after long year.How should I greet, with tears, with silence. "这是英国著名诗人拜伦的诗句,而世界上第一位程序员阿达·洛芙莱斯(Ada Lovelace),就是这位著名诗人的女儿,她编写了世界上第一个算法程序。1842 年,Ada 为巴贝奇剖析机编写求解伯努利方程的程序,写作了第一份“程序设计流程图”,被珍视为“第一位给计算机写程序的人”。因为查尔斯·巴贝奇(Charles Babbage)未能实现他的巴贝奇剖析机,这个算法未能在巴贝奇剖析机上执行。 这张写满数学算法的巨幅图表,被视为“第一个计算机程序”,由埃达·洛夫莱斯编写, 发表于 1843 年的一篇对于“剖析机” 的文章中。埃达对此给出精准形容如下:“这张表显示了运算过程中,机器各局部的所有间断变动。”尽管这个算法未能实现,但 Ada 对计算机科学的奉献毋庸置疑,1953 年,阿达之前对查尔斯·巴贝奇的《剖析机概论》所留下的笔记被从新颁布,并被公认对古代计算机与软件工程造成了重大影响。 ...

January 9, 2023 · 1 min · jiezi

关于算法:Python源码阅读堆的入堆出堆方法实现

基本概念优先队列(priority queue)是一种非凡的队列,取出元素的程序是依照元素的优先权(关键字)大小,而不是进入队列的程序,堆就是一种优先队列的实现。堆个别是由数组实现的,逻辑上堆能够被看做一个齐全二叉树(除底层元素外是齐全充斥的,且底层元素是从左到右排列的)。 堆分为最大堆和最小堆,最大堆是指每个根结点的值大于左右孩子的节点值,最小堆则是根结点的值小于左右孩子的值。 实现Python中堆的是以小根堆的形式实现,本文次要介绍Python源码中入堆和出堆办法的实现: """ 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30"""# push 将newitem放入底部,从底部开始把父结点往下替换def heappush(heap, item): """Push item onto heap, maintaining the heap invariant.""" heap.append(item) _siftdown(heap, 0, len(heap)-1)def _siftdown(heap, startpos, pos): newitem = heap[pos] # Follow the path to the root, moving parents down until finding a place # newitem fits. while pos > startpos: parentpos = (pos - 1) >> 1 parent = heap[parentpos] if newitem < parent: heap[pos] = parent pos = parentpos continue break heap[pos] = newitem# pop 顶部元素被弹出,把最初一个元素放到顶部,在把子节点(小于本人的)往上替换def heappop(heap): """Pop the smallest item off the heap, maintaining the heap invariant.""" lastelt = heap.pop() # pop tail in list # raises appropriate IndexError if heap is empty if heap: returnitem = heap[0] heap[0] = lastelt _siftup(heap, 0) return returnitem return lasteltdef _siftup(heap, pos): endpos = len(heap) startpos = pos newitem = heap[pos] # Bubble up the smaller child until hitting a leaf. childpos = 2*pos + 1 # leftmost child position while childpos < endpos: # Set childpos to index of smaller child. rightpos = childpos + 1 if rightpos < endpos and not heap[childpos] < heap[rightpos]: childpos = rightpos # Move the smaller child up. heap[pos] = heap[childpos] pos = childpos childpos = 2*pos + 1 # The leaf at pos is empty now. Put newitem there, and bubble it up # to its final resting place (by sifting its parents down). heap[pos] = newitem _siftdown(heap, startpos, pos)对于_siftup办法实现的解释能够看到python中_siftup办法的实现是和教科书以及直觉不太吻合的: ...

January 7, 2023 · 3 min · jiezi

关于算法:最新-CCF推荐国际学术刊物国际学术会议人工智能

原文:下载 | CCF举荐国内学术刊物&国内学术会议-人工智能 CCF举荐会议分为A、B、C三类,会议论文指“Full paper”或“Regular paper”(正式发表的长文),对于会议上其余模式发表的论文如Short paper、Demo paper、Technical Brief、Summary以及作为随同会议的Workshop等不计入目录思考的范畴。 CCF举荐会议《目录》是CCF认为值得计算机界研究者们发表研究成果的一个举荐列表,其目标不是作为学术评估的(惟一)根据,而仅作为CCF的举荐倡议供业界参考。因为畛域的穿插和视角的差别,同一会议在不同畛域存在意识上的差别是失常的,CCF举荐会议列表也只代表了CCF对这些会议和刊物的举荐倡议。会议的影响力并不间接和发表在其上的繁多论文的影响力产生分割,因而CCF不倡议任何单位将此《目录》简略作为学术评估的根据。 《目录》共分为以下10个局部: 计算机体系结构/并行与散布计算/存储系统计算机网络网络与信息安全软件工程/系统软件/程序设计语言数据库/数据挖掘/内容检索计算机科学实践计算机图形学与多媒体人工智能人机交互与普适计算穿插/综合/新兴关注并回复CCF举荐,获取完整版目录文件国内学术刊物-人工智能 国内学术会议-人工智能

January 6, 2023 · 1 min · jiezi

关于算法:CS-505-解答资讯

PaxosCS 505 Spring 2021Leader Election● Allows the system to skip phase 1 (prepare) when there is a stable leader● 2 possible designs (maybe more?)○ Proposers immediately start first phase of Paxos when they are “preempted”(Design outlined in PMMC, but we don’t recommend doing this)■ Can be inefficient - no bound on the number of preemptions that can occur■ Case when proposers compete with each other with higher proposal number○ Alternative: assume that the preempting node (higher proposal number) is the new“leader”. Wait for that node to drive the Paxos instance to a chosen value (or timeout).■ Still need to handle multiple simultaneous requests!○ Alternative 2: read the lab3 specLab 3 Tips● We recommend using PMMC as a starting place, but…○ Don’t code up PMMC exactly (lab3 spec provides guidance)○ Try to figure out what each part/role does and why it’s there● Every PaxosServer will be playing acceptor and learner roles○ If a server believes itself to be leader (or is trying to become leader), it will also play the proposerrole○ With regards to PMMC and implementing something similar, try to avoid making inner classes forroles like Scout or Commander, since that may blow up the state space● Read the lab3 spec about “sending” a message from a server to itself● If you receive a message with a higher ballot number than yours, stop beingleader (or stop trying to become leader)○ Not required for correctness, but makes it easier to implementGeneral Tips/What previous students said● Start early (applies to life too!)● According to a majority of students in previous offerings/quarters @ UW:Paxos is non-trivial● Students from UW also say to expect this to take more time than you think itwould and that they wish they started earlier and that we emphasized to themthat they should start earlier, hence this slide● Please startOther Resources● This Google tech talk: https://youtu.be/d7nAGI_NZPk● Stanford lecture: https://youtu.be/JEpsBg0AO6o● PMMC in a website: http://paxos.systems/Problem: Contention● If many proposers are sending values for the same slot at the same time,problems can occur○ Acceptors may reject accept requests if proposal number isn’t high enough● Don’t want to deal with contention for every log slot!● Solutions:○ Random timeouts○ Exponential backoff○ Stable leaderPMMC vs. Lab 3● Split into roles (replicas,acceptors, leaders, etc…)● Multi-threaded● Handles reconfiguration● Retries leader electionwhen preempted● One class (PaxosServer)○ Handles all the roles● Single-threaded● Ignores reconfiguration● Uses heartbeat messages todetermine when to begin leaderelectionPhase 2: Leader● Upon receiving a P2A, an acceptor should only accept it if the ballot number in the messagematches the acceptors ballot number○ This means the acceptor considers the sender to be the current leader○ Prevents split brain problems○ Can always reply with a P2B, just don’t update state if ballot numbers don’t match!● Need a way to sync logs between leader and all the acceptors. One way - when leader sends anaccept message, attach the leader’s log with the request. When acceptor replies, attach theacceptor’s log with the response. Then update/merge each side’s log. Can also sync up withheartbeat messages. Lots of different possible protocols and implementations to consider!Roles● As leader:○ Act as a proposer and acceptor from Basic Paxos○ Propose requests from clients■ First, check if the command has already been proposed, decided, or executed○ Keeps replicas up to date○ Send heartbeats to servers so they know the leader is alive■ Can include garbage collection information in these messages (more info soon)● As anyone else (not leader):○ Drop client requests○ Act only as an acceptor, not a proposer■ That is, until the server believes the leader died. Then it should start phase 1 (scoutphase)Garbage Collection● Problem: log (and thus memory usage) can grow indefinitely● Solution: garbage collect (delete) log entries that are no longer needed● Can discard log slots that everyone has already executed● Need a way to determine what slots other nodes are done with○ One solution: piggyback this information on heartbeat repliesGarbage Collection: 3 servers in the systemServer1 (leader):Latest executed slot: 4Server2:Latest executed slot: 4Server3:Latest executed slot: 3Hasn’t heard about slot 4Can garbage collect slots 1-3Garbage Collection: 5 servers in the systemServer1 (leader):Latest executed slot: 4Server2:Latest executed slot: 4Server3:Latest executed slot: 3Hasn’t heard about slot 4Cannot garbage collect anything untilall servers have executed a slotServer4:Latest executed slot: N/AServer5:Latest executed slot: N/ALab 3 Questions, q1Question: What’s the difference between a ballot number and a log slot?Answer:● Ballots are tuples of (round, leader) and are used during phase 1 of Multi-Paxos (analogous to proposal numbers from Basic Paxos).● Log slots are more general – namely, each log slot corresponds to aninstance of Paxos.○ Basic Paxos has no notion of log slots because it is only used to decide on a single value○ A single ballot can be used to decide multiple log slots■ This means the leader did not changeLab 3 Questions, q2Question: When are you done with a log slot? How can you make sure that thisis done efficiently?Answer: You are done when all servers in the Paxos group have executed therequest. You can piggyback messages to let everyone know not only what youare done with, but what you think everyone else is done with.● Note: Some log slots may have not been decided because the proposer may have died, stopping thepush to agreement on that log slot. You can resolve this by proposing a value, which will either driveany already accepted value to be chosen for that log slot, or will place a no-op into that log slot.Dealing with Log “Holes”/Proposing no-opsIf we have in our log:put(a, 1), ______, ______, append(a, 2)Do we know those empty log slots are decided? How can we push these logslots to completion?Your implementation needs to be able to handle "holes" in the Paxos log. That is,at certain points, a server might see agreement being reached on a slot but notprevious slots. Your implementation should still make progress in this case. ...

January 3, 2023 · 5 min · jiezi

关于算法:COMP24412-Prolog-分析

Academic Session: 2021-22Lab 1: PrologAssessed exercisesJoe and GilesSubmission is via git for this lab - see the section at the end of this document about submission.You should use your comp24412 repository (branch lab1) as a starting point. Please let me know ifrunning git checkout lab1 doesn’t work. You should see a file called database.pl.Learning ObjectivesAt the end of this lab you should be able to: Use the Prolog interactive mode to load and query Prolog programsModel simple constraint solving problems in PrologDefine recursive relations in PrologAdditionally, if you complete the formative exercises you should be able to:Explain issues surrounding termination in PrologUse an accumulator approach to detect cycles in reasoning1Part 0: Getting StartedThere are no mark available for the tasks in Part 0, but you will probably find them helpful beforestarting the assessed exercises. In fact, it is probably best to work through a few of the formativeexercises, described in the other document provided, even though they carry no marks.Running Prolog (read this)Open up a terminal and run swipl. You have just started the SWI-Prolog interactive mode, it shouldlook a bit like this.Welcome to SWI-Prolog (Multi-threaded, 64 bits, Version 5.7.11)Copyright (c) 1990-2009 University of Amsterdam.SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software,and you are welcome to redistribute it under certain conditions.Please visit http://www.swi-prolog.org for details.For help, use ?- help(Topic). or ?- apropos(Word).?-The ?- is the prompt where we can type things. To get out of interactive mode you shouldtype halt. (the . is necessary).The expected usage is that your Prolog program (knowledge base) is stored in a file andyou load this into the interactive mode and query it. For the warmup exercises we suggestyou create a file warmup.pl (open it in gedit or similar) and run swipl in the same directory. Alternatively,we can add queries directly to a program and run this from the command line using the plcommand but we assume that you are using the interactive mode.Warning. Not all Prolog implementations are the same. We are using SWI-Prolog in this coursebecause it is what is on the teaching machines. They also have Sictus Prolog if you prefer to use that.To load your warmup.pl file into interactive mode type?- [warmup].true.The true response tells you that the file was loaded correctly. You can now type queries directly inthe interactive mode. Add the line loves(mouse,cheese) and loves(monkey,banana) to warmup.pland run the following query?- loves(X,Y).X = mouse,Y = cheese(You probably need to reload the file). Recall that this returns an answer substitution (assignment tovariables). Type ; to get more answers or . to stop searching. In this example what happens to theanswers you get if you swap the two lines you have in warmup.pl?If you change warmup.pl you can reload it into interactive mode by typing [warmup] again. Youdon’t need to stop and restart interactive mode.The rest of this document contains the assessed exercises. Formative exercises in more of a tutorialstyle continue in the other document provided.2Part 1: Electrical InterferenceYou have joined a team working on the space program of a small country. The team is workinghard trying to design a probe to send to a distant planet. The electrical engineering department isworking on a list of components of the probe. For each pair of components, they have done tests tosee whether the components can be put close to each other without interfering with each other andbreaking. They have summarised their results so far in the following Prolog database (there is a copyof this in database.pl in the lab1 branch of your git repo.).component(antenna).component(transponder).component(radar).component(spectrometer).component(imu).component(camera).component(cpu).component(ram).safe_with(radar,cpu).safe_with(cpu,radar).safe_with(radar,imu).safe_with(imu,radar).safe_with(imu,camera).safe_with(camera,imu).safe_with(imu,cpu).safe_with(cpu,imu).safe_with(imu,ram).safe_with(ram,imu).safe_with(ram,cpu).safe_with(cpu,ram).safe_with(ram,camera).safe_with(camera,ram).safe_with(camera,transponder).safe_with(transponder,camera).safe_with(camera,cpu).safe_with(cpu,camera).safe_with(cpu,spectrometer).safe_with(spectrometer,cpu).safe_with(cpu,antenna).safe_with(antenna,cpu).safe_with(antenna,spectrometer).safe_with(spectrometer,antenna).safe_with(antenna,transponder).safe_with(transponder,antenna).safe_with(transponder,spectrometer).safe_with(spectrometer,transponder).Your task is to write software in Prolog to help the designers of the probe check that their designswill work, in that they only place components close together if the engineers have shown those componentsdon’t interfere. You should create a file electrical.pl to work in (make sure it is addedto the lab1 branch of your repo!). Note that to gain full marks you must provide an explanation ofwhat you have done (see mark scheme at the end).3Exercise 1To get started, write a predicate safe_list/1 (i.e. a predicate with functor name safe_list andtaking 1 argument) which takes a list of components and which succeeds if and only if every componentin the list is safe for use with every other component. For example safe_list([cpu,imu,radar])should succeed, but safe_list([ram,cpu,radar]) should fail. You may define extra predicates ifyou wish (this is true for all exercises in this lab).Now, the engineers don’t just want to study lists of components, they also want to analyse abstractdesigns for the probe. A design is a list where each element is either of the form part(C) for somecomponent C, or else of the form shield(L), where L is a design and the first element of L is of theform part(c). For example[part(imu), shield([part(cpu),shield([part(cpu)])])]is a design, but[part(imu), shield([shield([part(cpu)]),shield([part(cpu)])])]is not, because all the elements in the argument of the outermost shield are themselves of the formshield(X) – the first one is not of the form part(X) as required.You can assume that you will be given a properly formatted design. However, you may find it instructiveto write a predicate to check whether a design is properly formatted (no marks for this).The meaning of sheild(L) is that the elements of L have been electrically shielded from the outsideworld. That means that we can check whether a design is safe by checking whether all the partswhich are not inside shields are safe when used with each other, then recursively checking whetherthe contents of each shield are a safe design. For example, the design[part(radar), part(imu), shield([part(antenna),part(transponder)])]is safe, because the radar and imu are safe together, and the antenna and transponder are safetogether. But[part(radar), part(camera), shield([part(antenna),part(transponder)])]is not safe because it puts the radar and camera together without surrounding one of them withshielding, while[part(radar), part(imu), shield([part(antenna),part(camera)])]is not safe because the camera and antenna are not safe together.4Exercise 2Write a predicate safe_design/1 which, when given a design as input, succeeds if and only if thedesign is safe in the above sense. Note it is unlikely that you will be able to use the predicatesafe_list/1 from Exercise 1 directly, however the structure of your answer to this exercise is likelyto be similar. It is likely that you will need to define auxiliary predicates. You do not need to worryabout how your predicate behaves if the argument is not a design according to the definition above.If you are struggling with this part, you might find the next one easier.Since the finished probe is supposed to be carried into space by a rocket, it is important for it tobe as light as possible. The engineers are trying to use as little shielding as possible. As a firstapproximation, they want the software to count the number of times shield is used in a design.Exercise 3Write a predicate count_shields/2 which succeeds if and only if its second argument is the numberof times shield occurs in its first argument. It must be possible to use your predicate in the querycount_shields(D,N) where D is a design and N is a variable, so that Prolog returns the number.For examplecount_shields([part(imu),shield([part(ram),shield([part(radar)])]),shield([part(cpu)])],N)should return N = 3. You do not need to worry about the behaviour of your predicate if the firstargument is not a design according to the first definition.Finally, the engineers want to check that a design does not have any components missing. The ideais that they will provide a design and a list of components, and the software should be able to tell ifeach component in the list is used exactly once somewhere in the design.Exercise 4Write a predicate design_uses/2 which accepts a design and a non-empty list of components asarguments, and succeeds if and only if the first argument is a design, and the components used inthe design are exactly those listed in the list. Each element in the list must be used exactly once inthe design (if a component is repeated, it should be occur as many times in the design as there arerepetitions of it in the list). Note that the elements may appear in a different order in the designcompared to the list. Finally, the predicate should fail if the first argument is not a design as definedabove (we do count the empty list as a design).Before attempting to write design_uses/2, you should first write a predicate split_list/3 withthree arguments, which succeeds if the first argument can be split up into the other two arguments.For example, the query split_list([1,2,3],X,Y) should return the resultsIt may be helpful to think about going through the list element by element, and allocating each elementeither to the second or third argument, before recursively allocating the rest. You may thenlike to contemplate the results of the query split_list([1,2,3],[H],R).Make sure your test your solution(s). You should ensure that your solution works where componentsare repeated in the component list, for example, design_uses([part(imu),shield([part(imu)])],[imu,imu]).More testing data may be provided via Blackboard. Please keep an eye out for announcements.Exercise 5Once you have finished the exercises above, you should try running the query design_uses(D,[imu,cpu]).Ideally this will list all possible designs using one imu and one cpu. This will depend on ensuring yourprevious definitions are not unnecessarily restrictive. If this works, try running the querydesign_uses(X,[transponder,spectrometer,antenna,ram,cpu,imu,radar,camera]),safe_design(X),count_shields(X,2)although you might prefer to see if you can find a solution manually first.It might be that your Prolog code goes into an infinite loop! If you’re really interested in Prolog,ensure that your implementation of design_uses\2 does not go into an infinite loop for the inputgiven. Use comments to describe clearly when your implementation runs forever, and discuss whetherit would be efficient to run on large inputs, with clear reasoning for your claims.6Submission and Mark SchemeSubmission is via git. You must work on the lab1 branch and tag your submission as lab1 solution.The provided submit.sh script does this for you. Note that you must push your tagged commit toGitlab before the deadline (it is not good enough just to make the commit locally).Your work will be marked and returned to you with comments. We may automate some tests on yourcode so please do not edit the general layout (e.g. headings) of the provided file and make sure youuse the specified predicate names.The marking scheme (10 marks total) is as follows. (1 mark) for correct safe_list/1 (2 marks) for correct safe_design/1, 1 mark if missing a case (2 marks) for correct count_shields/2, 1 mark if missing a case (4 marks) with 2 marks for split_list/2 and 2 marks for the final design_uses/2 (1 mark) for an implementation of design_uses/2 which does not go into an infinite looptogether with clear and correct comments answering the questions asked at the end of Exercise5.You must provide explanations of the work you have done as comments in the submitted files. Theseshould go beyond standard comments in programs and should not simply reiterate the rules in Englishe.g. aim to explain the idea not the code. In all cases, up to half of the marks may be deducted if theexplanation of the code is not sufficient. You should aim to write in full sentences. You may includebrief examples.

January 3, 2023 · 9 min · jiezi

关于算法:ECMM410研究方法

ECMM410: Research Methodologies Course 2021-2022 Chris Edwards 60%, Mark Baldwin 20% and Pierre Friedlingstein 20% Backgroundr>The aim of the course is to introduce some of the ‘soft skills’ required to doresearch: for example, communication, literature review, critical thinking etc.Because of the mix of different subjects within the expected cohort, it is notpossible to cover ‘hard skills’ e.g. statistical analysis, as different students willhave a different baseline and have different requirements for their work. ...

January 3, 2023 · 7 min · jiezi

关于算法:ECOS3003问题集

ECOS3003 Problem set 1 of 3Problem set ECOS3003 Due date 1300 23 March Please keep your answers brief and concise. Excessively long and irrelevant answerswill be penalised. You can handwrite your answers if you wish. Consider the following game. Two workers A and B simultaneously choose toeither work on project 1 (P1) or project 2 (P2). The payoffs are as follow. If bothplayers opt for P1 the payoffs are 10 to A and 20 to B. If both players opt for P2, thepayoffs are 8 to A and 16 to B. If the choices are either P1 and P2 or P2 and P1 eachplayer gets 0.a. What are all of the Nash equilibria? ...

January 3, 2023 · 7 min · jiezi

关于算法:CS-15-CalcYouLater做法

CS 15 Project 2: CalcYouLaterFebruary 22, 2022ContentsIntroduction 3Preamble . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3Note on File I/O . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4Project Planning and Deliverables 5Week One . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5Deliverable #1: Design Checkoff . . . . . . . . . . . . . . . . 5Deliverables #2 and #3: DatumStack and parseRString . . . 6Week Two . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6Deliverable #4: CalcYouLater . . . . . . . . . . . . . . . . . . 6Datum Class 7Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7Datum Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7File Organization for the Provided Datum Files . . . . . . . . . . . 8DatumStack Class 10Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10DatumStack Interface . . . . . . . . . . . . . . . . . . . . . . . . . 10RPNCalc Class 12Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12RPNCalc Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . 12The ‘Simpler’ RPNCalc Commands . . . . . . . . . . . . . . . . . 12The ‘more Complex’ Commands . . . . . . . . . . . . . . . . . . . 13Any rstring . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13exec . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14if . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151CONTENTS 2Handling Errors in RPNCalc::run . . . . . . . . . . . . . . . . . . . 17Unrecognized Input . . . . . . . . . . . . . . . . . . . . . . . . 17Exception Handling . . . . . . . . . . . . . . . . . . . . . . . 17Errors while getting command parameters from the stack . . 18Error output prints to std::cerr . . . . . . . . . . . . . . . . . 19parseRString Specification 20parseRString Implementation . . . . . . . . . . . . . . . . . . . . . 20Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20cylc and cyl files 22Implementation Notes and Advice 23Notes Regarding the Starter Code . . . . . . . . . . . . . . . . . . 23Files to Submit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24DatumStack Implementation . . . . . . . . . . . . . . . . . . . . . 25Other Tips . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25Getting started . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25Makefile . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26README . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26Submitting Your Work . . . . . . . . . . . . . . . . . . . . . . . . . 27IntroductionPreambleWelcome to the second project! It’s a calculator, but it’s even more. It’salmost a real programming language! This is a more involved project, forwhich you have been given ample time, if you start right away.Do not try to do it in one sittingRead it right away. Jot down and draw ideas. It’s better to work on it in90 minute or 2 hour chunks of time. If you do that, and you’re organized,it will go smoothly. The stack implementation itself should be doable in asingle sitting. Be sure to note the three phases of the project. Come in totalk to one of us about your plan as early as you can.Note on File I/OFor this project, you’ll find knowledge you acquired about file I/O in Project1 helpful. In particular, the ability to pass a reference to an std::istreamto a function makes it easy to modularize your code by allowing a functionto process input from any input stream, whether it be std::cin or a streamthat you attached to a file using open.There is an additional piece here. C++ has a way for you to treat astd::string as if it were an input stream! It has a class,called std::istringstream. Its constructor and an example of how to usea std::istringstream for input can be found here. A istringstreamhas eof and fail member functions, just like std::cin or any other inputstream. Here is also a tutorial on string streams. The idea forour purposes is to make an std::istringstream from a std::string,and then pass that std::istringstream to a function that requests anstd::istream &, and it will work!3CONTENTS 4IntroductionIn this project you will implement a Reverse Polish Notation (RPN) calculator.RPN is also known as “postfix” notation1. This means that theoperator comes after its operands rather than in between. For example:• 3 4 + is equal to 7• 3 4 * is equal to 12• 1 2 - is equal to -1 (note the order)• 8 2 / is equal to 4 (note the order)Cool fact: RPN does not need any parentheses as long as each operatorhas a fixed number of operands (which is the case in this assignment). Forexample, the infix expression:5 + ((1 + 2) * 4) - 3can be written in postfix notation as follows:5 1 2 + 4 * + 3 -Your RPNCalc will support more than just integers, however! It will supportDatum objects! More on this in a moment.1The notation you’re used to, with the operator between the operands is called “infix”notation.Project Planning andDeliverablesBefore writing any functions, sit down and read the assignment specificationin full. There is a lot of complexity here! Then, begin to plan your solution.It would be prudent to organize and plan your solution to be as modular aspossible. Use helper functions! Doing this initial planning will be extremelyhelpful down the road when it comes to testing and debugging; it also helpsthe course staff more easily understand and read your work (which can onlyhelp you). It is not advisable that you sit down and attempt to write thisin one sitting, particularly if that sitting is close to the deadline. For thatreason, the CS 15 course staff has come up with a project implementationplan, split into three required (read: graded) phases:Week OneDeliverable #1: Design CheckoffGo into office hours and talk to a TA about your plan. Bring some drawingsof your data representations - how you imagine your data will flow betweenstructures. This helps twofold: you plan out your project and get your brainworking on it in the background, and also you get design feedback beforeit’s too late. You must have physical drawings to show the TA. The TA willnot look at any code since this checkout is designed to give feedback on yourdesign only, not any code (light pseudocode is allowed). TAs will check offyour design and reserve the right to not check off your design if you do nothave drawings (and pseudocode) to show or if a TA feels like your designwas not thoroughly mapped out enough. Please sign up for design check offlinked here5CONTENTS 6Deliverables #2 and #3: DatumStack class and parseRStringWrite and submit the DatumStack class and parseRString function (theseare described in detail under sections of their own names below). These arenot expected to be strenuous exercises, but have been known to occasionallyhide latent bugs that mess up the rest of your RPNCalc. So, start them early,get them right, and make sure they are well-tested.Week TwoDeliverable #4: CalcYouLaterWrite CalcYouLater! (described in detail below) Implement some of theless involved operations first. Then do the more complicated operations.Datum ClassIntroductionBefore diving in to the details of the RPNCalc and DatumStack clases, wewill go over the Datum class. A Datum object is essentially a container forone of three things:• int• bool• rstring (short for RPN string)The type of the value contained by any given Datum object is chosen fromthe above three options at construction-time, and does not change duringthe lifetime of that Datum object. We have coded the Datum class for you,but it would be worth your while to understand the interface.Datum Interface• Four Constructors: one constructor for each type a Datum object cancontain, plus a copy constructor. Note that there is no default constructor.Also note that, under the hood, rstrings are represented asC++ strings.1 Datum (int i) ;2 Datum ( bool b) ;3 Datum ( string s) ;4 Datum ( const Datum &d) ;• A destructor• An assignment operator overload7CONTENTS 8• Three type query functions:1 bool isInt () ;2 bool isBool () ;3 bool isRString () ;• An equals (==) operator for comparing two different Datum objects.This allows us to call, e.g., d1 == d2 where d1 and d2 are instancesof the Datum class. If d1 and d2 contain values of different types, thiswould return false. If d1 and d2 contain values of the same type,then the underlying values will be compared.• The less-than (<) operator for Datum holding integers. Using the lessthanoperator and the is-equal-to operator, we can build less-than-orequal(<=), greater-than-or-equal (>=), and greater-than (>). Use ofany of these operators on Datum which hold booleans or rstrings willraise a std::runtime_error with the message “datum_not_int”.• Three data access functions:1 int getInt () ; // throws " datum_not_int "2 bool getBool () ; // throws " datum_not_bool "3 std :: string getRString () ; // throws " datum_not_rstring "These functions each throw an std::runtime_error with the associatedmessage above if they are called on a Datum of the wrong type.For instance, if I have a Datum that contains a boolean value, and Icall getRString() on it, it will raise a std::runtime_error with themessage datum_not_rstring.• toString(), a function that creates a string representation of theDatum. This is useful for printing and debugging.File Organization for the Provided Datum FilesThe Datum class is given to you as two files: Datum.h and Datum.o. Datum.hcontains the interface of the Datum class; Datum.o contains a pre-compiledobject file. That is, it is a non-human-readable file which was compiled froma .cpp file, and it contains all of the working machine code that you can usein your project, but does not give you any information about how it works.What it does, however, can be gleaned from Datum.h (the interface). To usethe Datum class, you must #include "Datum.h" at the top of whichever fileCONTENTS 9will use it, and you must link Datum.o with your compiled code. You canreview the Makefile lecture and lab for a reminder of how to link with a .ofile.DatumStack ClassIntroductionThe DatumStack class will maintain a stack of Datum objects, and will beused heavily by the RPNCalc class. Part of your Week 1 assignment is to toimplement this interface.DatumStack InterfaceYou DatumStack class must have the following interface (all the followingmembers are public):• Two constructors as follows:◦ A default constructor, which takes no parameters and initializesan empty stack.◦ A constructor which takes an array of Datum and an integerspecifying the size of the array as parameters and creates a stackinitialized so that the elements of the array are on the stack withthe array’s element 0 pushed on first and it’s (size - 1)th elementat the top of the stack. Example:1 Datum data [2] = { Datum (5) , Datum ( true ) };2 DatumStack d(data , 2) ;3 // d now has a true Datum as the top element• If necessary, define the Big Three (destructor, copy constructor, assignmentoperator).• An isEmpty function that takes no parameters and returns a booleanvalue that is true if this specific instance of the DatumStack class isempty and false otherwise.10CONTENTS 11• A clear function that takes no parameters and has a void return type.It makes the current stack into an empty stack.• A size function that takes no parameters and returns an integer valuethat is the number of Datum elements on the stack.• A top function that takes no parameters and returns the top Datumelement on the stack. NOTE: It does not remove the top elementfrom the stack. If the stack is empty, it throws a std::runtime_errorexception with the message “empty_stack”.• A pop function that takes no parameters and has a void return type.It removes the top element on the stack. NOTE: It does not returnthe element. If the stack is empty it throws a std::runtime_errorexception with the message “empty_stack”.• A push function that takes a Datum element and puts it on the top ofthe stack.RPNCalc ClassIntroductionThe interface for the RPNCalc class is rather straightforward—the complexityis not in the number of functions, but rather is in the logic of processingthe commands that come to the run function.RPNCalc Interface• Define a default constructor which takes no parameters and initializesthe RPNCalc object.• Define a destructor that destroys/deletes/recycles any heap-allocateddata you may have used in the RPNCalc instance.• Define a run function that takes no parameters and returns nothing.This function reads in commands from standard input (std::cin).Each command can be read as a string and commands will be separatedby whitespace. Commands do not have to be on different lines. Seebelow for details.The ‘Simpler’ RPNCalc CommandsThe supported operations will be extended by the “harder” commands, butimplement these simpler commands first and get them working before continuingon.• A number causes a Datum containing the number to be pushed ontothe stack.• #t causes a Datum with the boolean true to be pushed on the stack.12CONTENTS 13• #f causes a Datum with the boolean false to be pushed on the stack.• not reads and pops the top element off the stack, a boolean, and causesa Datum with the opposite boolean value of the popped element to bepushed on the stack.• print prints the value on the top of the stack to std::cout (withoutpopping it) followed by a new line.• clear clears the calculator, emptying the stack.• drop causes the top element on the stack to be removed.• dup duplicates the top element on the stack.• swap swaps the top two elements on the stack.• quit, quits the calculator completely. When the program quits, itprints the following message to std::cerr: “Thank you for usingCalcYouLater.\n” (It should print this message whether it quits withthe quit command or by reaching the end of input on std::cin).• The operators +, -, *, /, or mod. Any of these causes the top twoelements (which must both be integers) to be popped off the stack,the operation to be performed on them (addition, subtraction, multiplication,division, or remainder), and a Datum with the result to bepushed on the top of the stack. The first operand of the operation isthe first (deeper) item on the stack. NOTE: The result does notprint.• The operators <, >, <=, >=, or ==. Any of these causes the top twoelements to be popped off the stack, the operation to be performed onthem (some kind of logical comparison) and a Datum with the result(a boolean) to be pushed on the top of the stack. The first operandof the operation is the first (deeper) item on the stack. NOTE: Theresult does not print.The ‘more Complex’ CommandsAny rstringYou can think of an rstring as a sequence of commands to be saved andexecuted later. For our purposes, an rstring will be defined as a sequenceof characters that follows this pattern:CONTENTS 14• The sequence must begin with "{ " (note the spacing!).• The sequence must end with " }" (note the spacing!).Any rstring that is provided as input to RPNCalc will be put inside of aDatum as an std::string, and the Datum will be pushed onto the stack. Toclarify, “rstring” itself is not a command; rather, an example of a commandthat would be parsed as an rstring and pushed onto the stack would be“{ 2 8 + }”. Another example would be “{ 2 + }”.Note: The braces must match up, and the spacing around thebeginning and ending braces must be correct. Also, rstrings canbe nested - to see an example of nested rstrings, read on aboutif.Clearly, processing rstrings will be important for the success of yourRPNCalc class. Thus, part of your Week 1 assignment is to implement afunction to parse rstrings. While reading in input, once you read a "{ ",you should call this parsing function. See the section titled parseRStringSpecification (below) for details.execexec takes the topmost element on the stack, which must be an rstring, andprocesses its contents as a sequence of commands. If the topmost elementof the stack is not an rstring, it should print “Error: cannot execute nonrstring\n” to std::cerr, and your program should continue to accept input.filefile pops the top element off of the stack, which must be an rstring. Ifit is not an rstring it should print “Error: file operand not rstring\n” tostd::cerr, and continue to accept input.For example, the rstring might be “{ square.cylc }”, in which casethe filename is “square.cylc”. The contents of the named file is then read andprocessed as if its commands had been typed into the command loop. If thefile cannot be opened or read, the message “Unable to read FILENAME\n”(where “FILENAME” is replaced with the name of the file specified in thecommand) is printed to std::cerr. The program does not crash or throwan exception. The command loop then continues reading data from its lastinput source.CONTENTS 15ifif Overviewif has a few steps. The command if: ...

January 3, 2023 · 29 min · jiezi

关于算法:IX-520002平台设备

_IX 520002 Platforms and DevicesBatch File Assessment_Study Block 2: 07/02/2022 to 15/04/2022Reports due: 18 March 2022.Submission: Upload soft copy to Moodle.Course Leader: Reza RafehWeighting/Contribution: 10% to final markMarks out of: 100 marksLearning outcomes covered: LO 1Version: 2022.1__Platforms and Devices Block 1, 2022Assessment Task: Batch fileAssessment OverviewCreate a batch file that will carry out tasks detailed in this document, on a Windows PC. Thisassessment relates to learning outcome 1.Late Submission, Reassessment, ExtensionsThe School process in relation to Submissions, Extensions, Resubmissions and Re-sits complies withOtago Polytechnic Policies. Students can view policies on the Otago Polytechnic Website located athttp://www.otagopolytechnic.a...Resubmission is where an original assessment is returned to the student for minor reworking andthen being resubmitted for final grade. Where a student achieves a D grade for any assessment, anapplication for resubmission may be made to the Head of School. A maximum of two resubmissionswill be permitted in any one year for any student.Resubmissions are completed within a short time frame (usually no more than five working days)and usually must be completed within the timing of the course to which the assessment relates.Resubmissions will be available only to students who have made a genuine attempt at the firstassessment opportunity. The maximum grade awarded for a resubmission will be C-.Information about late submission and extensions can be located in the Course Outline.Platforms and Devices Block 1, 2022IX520002 Platforms and DevicesBatch File (worth 10% of final mark)Due18 March 2022, 5 pm.TaskCreate a batch file that will carry out tasks detailed in this document, on a Windows PC.File HeadersAt the beginning of the file, insert a text header made up of non-executable comments (thereis a command to do this – look in the HELP list), labelling and describing the followinginformation on multiple lines:• The name of the batch file• A paragraph describing the purpose of the script• Your name and student ID• The course name, your year and semesterAfter the header comment, insert a statement that outputs the file name to the screen (thereis a command to do this – look in the HELP list.)File ContentsInsert command statements to perform the actions numbered 1 through 20 on the list ofactions given on pages 4 and 5 of this document.Before each set of command statements referred to above, insert statements that outputto the screen a description of each action that the command statements will perform.The displayed output of each statement should contain the following information:• A blank line, to make the output more readable• A section containing:o The action numbero The name of the command (or commands) that you have decided to useo A brief description of what the command is supposed to do (you can copy thisfrom the list of actions if you wish)After each action from the list, insert a statement to display another blank line. Theninsert a statement to suspend processing of the script, to enable the examiner to look at Platforms and Devices Block 1, 2022the script file’s output before pressing the Enter key to continue (there is a command todo this – look in the HELP list.)Throughout the batch file, ensure that the lines within the file are not displayed to thescreen as they are processed (there is a command to control this – look in the HELP list),except when it is necessary to demonstrate the working of the batch file.LayoutEnsure that the text within each batch file is laid out neatly and consistently. In particular:• Use uppercase letters for all command line commands, switches and switch values• Use consistent lettering for all command line command parameters, such as file names• Leave blank lines around each section within each file• Use spaces and tab characters to line up any columns• Check your spelling, punctuation and grammar throughoutSubmission• Change the file extension of your batch file from .bat to .txt• Submit using the link on Moodle.Platforms and Devices Block 1, 2022Batch File: [YOURNAME].BAT (e.g. SIMON.BAT or JACINDA.BAT) ...

January 2, 2023 · 6 min · jiezi