A method for controlling an automated drilling operation in the hydrocarbon industry, where the automated drilling operation is subject to a change in one or more operating conditions, can be controlled by at least one parameter and is monitored by at least one sensor (92, 94, 95) providing an input data stream, comprising: receiving the stream of input data from the at least one sensor, comprising measurements indicative of depth-of-cut, weight-on-bit and drill-bit rotational speed measurements; upon receiving a new data item in the input data stream, using a processor to postulate that the input data stream is segmented according to a plurality of possible segmentations, wherein each of the plurality of possible segmentations comprises a plurality of segments divided by one or more changepoints (405, 407, 409, 411), and wherein the changepoints are indicative of a change in at least one of the one or more operating conditions; evaluating each of the plurality of possible segmentations by: fitting portions of the input data corresponding to each segment in the segmentation being evaluated to a model corresponding to the segment in the segmentation being evaluated; and determining how well the models for the segments of the segmentation being evaluated fit the portions of the input data corresponding to each segment of the segmentation being evaluated; generating an output in the form of a functional relationship defining rate-of-penetration as a function of weight-on-bit and drill-bit rotational speed from at least one of the plurality of possible segmentations and the models corresponding to the segments of the at least one of the plurality of possible segmentations; determining operating constraints defining a safe operating envelope as a function of drill-bit rotational speed and weight-on-bit; determining the rotational speed and weight-on-bit parameters that provide a maximum rate-of-penetration location within the safe operating envelope; outputting a combination of drill-bit rotational speed and weight-on-bit to move the drill-bit rotational speed and weight-on-bit towards the rotational speed and weight-on-bit parameters for the maximum rate-of-penetration location; and using the output to control at least one parameter of the automated drilling operation. receiving the stream of input data from the at least one sensor, comprising measurements indicative of depth-of-cut, weight-on-bit and drill-bit rotational speed measurements; upon receiving a new data item in the input data stream, using a processor to postulate that the input data stream is segmented according to a plurality of possible segmentations, wherein each of the plurality of possible segmentations comprises a plurality of segments divided by one or more changepoints (405, 407, 409, 411), and wherein the changepoints are indicative of a change in at least one of the one or more operating conditions; evaluating each of the plurality of possible segmentations by: fitting portions of the input data corresponding to each segment in the segmentation being evaluated to a model corresponding to the segment in the segmentation being evaluated; and determining how well the models for the segments of the segmentation being evaluated fit the portions of the input data corresponding to each segment of the segmentation being evaluated; generating an output in the form of a functional relationship defining rate-of-penetration as a function of weight-on-bit and drill-bit rotational speed from at least one of the plurality of possible segmentations and the models corresponding to the segments of the at least one of the plurality of possible segmentations; determining operating constraints defining a safe operating envelope as a function of drill-bit rotational speed and weight-on-bit; determining the rotational speed and weight-on-bit parameters that provide a maximum rate-of-penetration location within the safe operating envelope; outputting a combination of drill-bit rotational speed and weight-on-bit to move the drill-bit rotational speed and weight-on-bit towards the rotational speed and weight-on-bit parameters for the maximum rate-of-penetration location; and using the output to control at least one parameter of the automated drilling operation. fitting portions of the input data corresponding to each segment in the segmentation being evaluated to a model corresponding to the segment in the segmentation being evaluated; and determining how well the models for the segments of the segmentation being evaluated fit the portions of the input data corresponding to each segment of the segmentation being evaluated; generating an output in the form of a functional relationship defining rate-of-penetration as a function of weight-on-bit and drill-bit rotational speed from at least one of the plurality of possible segmentations and the models corresponding to the segments of the at least one of the plurality of possible segmentations; determining operating constraints defining a safe operating envelope as a function of drill-bit rotational speed and weight-on-bit; determining the rotational speed and weight-on-bit parameters that provide a maximum rate-of-penetration location within the safe operating envelope; outputting a combination of drill-bit rotational speed and weight-on-bit to move the drill-bit rotational speed and weight-on-bit towards the rotational speed and weight-on-bit parameters for the maximum rate-of-penetration location; and using the output to control at least one parameter of the automated drilling operation.